语文数学都大于60为合格,只用一次select,查出合格人数合不合格人数

失去了.png

SQL 帆软用户XG147iA2UW 发布于 2022-8-23 10:24
1min目标场景问卷 立即参与
回答问题
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
2
snrtuemcLv8专家互助
发布于2022-8-23 10:32

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

最佳回答
1
HandsomeBoyLv5见习互助
发布于2022-8-23 10:30

select count(1) 合格人数 from 表名 where chinese>60 and math>60

union all 

select count(1) 不合格人数 from 表名 where chinese<=60 or math<=60

最佳回答
0
Z4u3z1Lv6专家互助
发布于2022-8-23 10:32

SELECT FL,COUNT(STUDENTNO) [SL] FROM (

SELECT *,(CASE WHEN CHINESE>60 AND MATH>60 THEN '合格' ELSE '不合格' END) [FL] FROM TABLE

) A GROUP BY FL

image.png

最佳回答
0
biubiuskyLv3见习互助
发布于2022-8-23 11:23(编辑于 2022-8-23 11:25)

写法应该好几种,只用一次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)

  • 3关注人数
  • 500浏览人数
  • 最后回答于:2022-8-23 11:25
    请选择关闭问题的原因
    确定 取消
    返回顶部