51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

mysql 数据库case判断语句

mysql 数据库case判断语句

case when 条件 then 结果 end

mysql> select teacher.tname,course.cname,concat(floor(count(case when sc.score>=60 then 1 end)/count(*)*100),"%") from teacher  
join course on teacher.tno=course.tno  
join sc on course.cno=sc.cno  
group by teacher.tno,course.cno;
+--------+--------+--------------------------------------------------------------------------+
| tname  | cname  | concat(floor(count(case when sc.score>=60 then 1 end)/count(*)*100),"%") |
+--------+--------+--------------------------------------------------------------------------+
| oldboy | linux  | 100%                                                                     |
| xiaoQ  | python | 66%                                                                      |
| xiaoA  | mysql  | 75%                                                                      |
+--------+--------+--------------------------------------------------------------------------+
3 rows in set (0.00 sec)

案例参考: 及格率 https://www.baimeidashu.com/11730.html

赞(4)
未经允许不得转载:工具盒子 » mysql 数据库case判断语句