select classno, sum(case when chinese>59 and math>59 then 1 else 0 end) as 合格人数,sum(case when chinese<60 and math<60 then 1 else 0 end) as 不合格人数 from 表 group by classno
select count(1) 合格人数 from 表名 where chinese>60 and math>60
union all
select count(1) 不合格人数 from 表名 where chinese<=60 or math<=60
SELECT FL,COUNT(STUDENTNO) [SL] FROM (
SELECT *,(CASE WHEN CHINESE>60 AND MATH>60 THEN '合格' ELSE '不合格' END) [FL] FROM TABLE
) A GROUP BY FL
写法应该好几种,只用一次select的话,这样写貌似也能达到
select
count(t1.studentno) as 合格人数,
(count(t.studentno)-count(t1.studentno)) as 不合格人数
from tablename t
left join tablename t1
on t1.studentno=t.studentno and (t.chinese>60 and t.math>60)