50个SQL语句(MySQL版)问题二十三
--------------------------表结构--------------------------
student(StuId,StuName,StuAge,StuSex) 学生表
teacher(TId,Tname) 教师表
course(CId,Cname,C_TId) 课程表
sc(SId,S_CId,Score) 成绩表
----------------------------------------------------------
问题二十三:统计打印各科成绩各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[<60]
SELECT sc.S_CId "课程ID", course.Cname "课程名称",SUM(CASEWHEN sc.Score BETWEEN85AND100THEN1ELSE0END) "[100-85]",SUM(CASEWHEN sc.Score BETWEEN70AND85THEN1ELSE0END) "[85-70]",SUM(CASEWHEN sc.Score BETWEEN60AND70THEN1ELSE0END) "[70-60]", SUM(CASEWHEN sc.Score<60THEN1ELSE0END) "[<60]"FROM sc,coursewhere sc.S_CId=course.CIdGROUPBY sc.S_CId;
答案仅供参考,不一定完全正确,若发现错误或有更好的,欢迎评论,互相交流,一起成长!!!
以上是 50个SQL语句(MySQL版)问题二十三 的全部内容, 来源链接: utcz.com/z/533982.html