【发布时间】:2013-06-28 05:53:55
【问题描述】:
我有以下表格布局
表a
Teacher Students
Mohan pankaj
Mohan sudeepa
Mohan sujitra
Mohan Sumit
表 b(第一学期分数)
Pankaj Maths 50
Pankaj English 40
Pankaj Physics 60
Sudeepa Chemisty 40
Sujitra Physic 10
Sujitra English 40
Sujitra Hindi 70
表 c(第 2 学期分数)
Pankaj Chemistry 50
Pankaj English 40
Pankaj Physics 60
Sudeepa Science 40
Sujitra Physic 10
Sujitra Maths 40
Sujitra Hindi 70
我希望输出为:-
hindi 140.00
maths 40.00
physics 10.00
science 40.00
chemistry 40.00
english 40.00
physics 10.00
我写了查询
select subject,sum(marks) from sample.b where
student in ( select student from sample.a where teacher='mohan')
group by subject
union all
select subject,sum(marks) from sample.c
where student in ( select student from sample.test where teacher='mohan')
group by subject
我得到的结果是
hindi 70.00
maths 40.00
physics 10.00
science 40.00
chemistry 40.00
english 40.00
hindi 70.00
physics 10.00
*问题* Same subjects marks are not adding up..
【问题讨论】:
-
附带说明一下,您的数据库设计存在问题 - 您是否打算为每个不同的学期添加一个表格?最好有一个“Class_Taken”表(或类似表),并为学年和学期添加几个额外的列。