数据库查询--统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[0-60]及所占百分比

lliu26 lliu26 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
create table Student(S# varchar(10),Sname varchar(10),Sage date,Ssex varchar(10));
create table Course(C# varchar(10),Cname varchar(10),T# varchar(10));
create table Teacher(T# varchar(10),Tname varchar(10));
create table SC(S# varchar(10),C# varchar(10),score decimal(18,1));

有以上4个表,要求得到下面的数据:
统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[0-60]及所占百分比

除了最后的百分比,剩下的信息都能通过下面的sql语句获得:

select m.C# , m.Cname , (
case when n.score >= 85 then '85-100'
when n.score >= 70 and n.score < 85 then '70-85'
when n.score >= 60 and n.score < 70 then '60-70'
else '0-60'
end) as px,
count(1)
from Course m , sc n
where m.C# = n.C#
group by m.C# , m.Cname , (
case when n.score >= 85 then '85-100'
when n.score >= 70 and n.score < 85 then '70-85'
when n.score >= 60 and n.score < 70 then '60-70'
else '0-60'
end)
order by m.C# , m.Cname , px


请教:如何修改上面的sql,以得到包括百分比在内的所有数据?
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
lliu26
Oracle 17,133 成员 55,258 内容