MySQL数据case when查询怎么将0的数据显示出来

问题遇到的现象和发生背景

img

img

问题相关代码,请勿粘贴截图

SELECT grade_temp AS '分数段',COUNT(*) AS '人数' FROM(
SELECT Grade,
CASE
WHEN Grade < 60 THEN '60分以下'
WHEN Grade BETWEEN 60 AND 80 THEN '60-80'
WHEN Grade BETWEEN 80 AND 100 THEN '80-100'
END AS grade_temp
FROM sc GROUP BY Sno
)AS USER GROUP BY grade_temp;

运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

想要实现如截图一样显示0的区间

可以group by 后面跟着你的case when语句。
在select的时候你只用count(*)

如果你表里面本就没有对应的数据,是count不出一条新的记录的。此时可以多次查询然后再union all或者分成不同的字段查询再进行行列转换

select
(case when sc.score<60 then '60分以下'
when sc.score>=60 and sc.score<80 then '60-80'
else '80-100' end) 分数段
,count(*) 人数
from sc
group by
(case when sc.score<60 then '60分以下'
when sc.score>=60 and sc.score<80 then '60-80'
else '80-100' end);