方式1:
select
(case
when score<60 then '<60'
when score<70 then '60-70'
when score<80 then '70-80'
when score<90 then '80-90'
else '90-100'
end
) as level,
count(*) as count
from students
group by level
方式2:
select
ELT(INTERVAL(t.score,0,60,70,80,90,100),'<60','60-70','70-80','80-90','90-100') as level,
COUNT(t.score) as count
from students t GROUP BY level;
利用interval
划出4个区间,再利用elt
函数将4个区间分别返回一个列名。
结果: