翻翻過(guò)去那場(chǎng)雪
2018-08-01 21:09:57
問(wèn)題描述一張表,id class score,一條SQL語(yǔ)句,獲得每個(gè)班級(jí)大于60分和小于60分的個(gè)數(shù),結(jié)果為:班級(jí) 大于60 小于60A1 2 3A2 1 2補(bǔ)充采納了答案,我在想有沒(méi)有更簡(jiǎn)單或者效率更高的sql語(yǔ)句
2 回答

慕斯709654
TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊
select class count(score as sc_under60) count(score as sc_above60)
from 表
where sc_under60 < 60 and sc_above60 > 60
group by class;
是這個(gè)意思么?

藍(lán)山帝景
TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
是這樣吧。
SELECT
class as 班級(jí),
(select count(score) from score c1 where score > 60 and c.class = c1.class) as 大于60,
(select count(score) from score c2 where score < 60 and c.class = c2.class) as 小于60
FROM
score c
GROUP BY
class;
添加回答
舉報(bào)
0/150
提交
取消