欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

请教大家一个SQL的问题.

程序员文章站 2024-04-04 09:11:23
...
有一个test数据库,里面有一张学员表student,有三个字段,class,name,score,分别表示班级,姓名,成绩,问:查询每个班级的及格人数和不及格人数,输出格式是class,及格人数,不及格人数

这个该怎么写呢?


回复讨论(解决方案)

select class,sum(case score >=60 then 1 else 0 end) as '及格人数',sum(case score    

select class,(select count(*) from student where class=stu.class and score >=60 ) as '及格人数',(select count(*) from student where class=stu.class and score   

哦,写错了。更正:

select class,(select count(*) from student where class=stu.class and score >=60 ) as '及格人数',(select count(*) from student where class=stu.class and score