Bootstrap

SQl复杂查询

计算每个班的语文总成绩和数学总成绩,要求科目中低于60分的成绩不记录总成绩。

tb_score结构数据:

namechinesemaths
A8998
B9989
C5566
D8866
E5566
F8899

tb_class表结构数据:

stunameclassname
AC1
BC2
CC3
DC2
EC1
FC3

参考代码

select classname,sum(if(chinese<60,0,chinese)) as chinese,
sum(if(maths<60,0,maths)) as maths
from tb_score s,tb_class c
where s.name=c.stuname
group by classname;

;