sql 笔试题

表stuinfo

idsubjectscore
1语文78
1数学60
1英语90
2语文50
2数学44
2英语55
3语文45
3数学44
3英语90

 

现在要求 如下 查出每个编号的总成绩 并且要大于200分

idscore→(总成绩要大于200分)
1228

 

请写出sql语句?

 


问题补充:
select id,sum(score) s from table group by id having s>200; 其中having s>200时 报个错误说是没有列 s, 应该就写成having > sum(score) 不知道是否还有其他的写法

[code="sql"]select id, s score from (
select id,sum(score) s
from stuinfo
group by id
) t
where t.s > 200[/code]

mysql> select id,sum(score) s from table group by id having s>200;

做一次子查询即可。

1楼的方法是最好的吧,只是语法上有点小问题而已,其它的是这一方法的变种,不好

如是确定是每一编号都有3个,不求和,求平均也是一样的,反正意思一样,

select id,sum(score) s from table group by id having sum(score) >200;

select id,sum(score) s from table group by id  where s>200;