mysql统计数学课的及格人数_SQL 查询某门课程及格的总人数以及不及格的总人数以及没成绩的人数...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:11   2046   0

展开全部

1、创建测试表,

create table test_score(class_id varchar2(20), student_id varchar2(20), score number);

30e7f3f3c41af60f3f2c6cfe7c42c750.png

2、插入测试数据

insert into test_score values ('C07', 1001, 50);

insert into test_score values ('C07', 1002, 72);

insert into test_score values ('C07', 1003, 85);

insert into test_score values ('C07', 1004, 91);

insert into test_score values ('C07', 1005, 48);

insert into test_score values ('C07', 1006, 79);

insert into test_score values ('C07', 1007, null);

733da7df4c833a3278ec03432a212972.png

3、查询表e69da5e6ba9062616964757a686964616f31333431373864的记录,select t.*, rowid from test_score t;

5f67d59169b6641d472352feb9c20457.png

4、编写sql,查询某某课程及格的总人数以及不及格的总人数以及没成绩的人数,

select class_id,

count(distinct case when score < 60 then student_id end) s1,

count(distinct case when score >= 60 then student_id end) s2,

count(distinct case when score is null then student_id end) s3

from test_score t group by class_id,

a49280350bd141b724296a38dca3ce1b.png

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP