统计出每门课程各个成绩等级的学生数量
2016-12-06 10:47
288 查看
学生成绩表sc(id,sid,cid,score),id是sc表的主键,sid是学生编号,cid是课程号,score是对应的分数。分数在90-100之间的等级是A,在80-90之间的等级是B,在70-80之间的是C,在60-70之间的是D,60分之下的是E。现要求统计出每门课程各个成绩等级的学生数量。
SQL语句如下:
如sc表的内容如下:
查询的结果如下:
SQL语句如下:
select cid, sum(case when score>=90 and score<=100 then 1 else 0 end) A, sum(case when score>=80 and score<90 then 1 else 0 end) B, sum(case when score>=70 and score<80 then 1 else 0 end) C, sum(case when score>=60 and score<70 then 1 else 0 end) D, sum(case when score<60 then 1 else 0 end) E from sc group by cid
如sc表的内容如下:
查询的结果如下:
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- 解决mysql 开启logbin 导致存储过程报错
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志