Oracle 根据不同成绩,对应不同等级信息

1 --查询每一颗成绩的:优秀、良好、不良的数量
2 --校园需要一张各科成绩状态统计表,格式如下:
3 
4 --科目名称  优秀人数  良好人数    不良人数
5 --高等数学    5          12       2
6 --英语       8          18       1

先创建一个视图,然后把这个视图当做一个表,对这个视图进行操作

create view test
as
select cid ,case
                    when cmark >=90 then '优秀'
                    when cmark >=80 then '良好'
                    else '不良'
                    end tip
from mark m
1 select (select cname from course where cid=c.cid) 课程名,
2               (select count(*) from test t where c.cid=t.cid and t.tip='优秀' ) 优秀,
3               (select count(*) from test t where c.cid=t.cid and t.tip='良好' ) 良好,
4               (select count(*) from test t where c.cid=t.cid and t.tip='不良' ) 不良
5 from test b join course c on b.cid = c.cid
6 group by c.cid

 

posted @ 2020-07-03 14:31  勤快的懒羊羊  阅读(725)  评论(0编辑  收藏  举报