mysql如何统计每个专业分数段的人数
发布时间:2020-03-20 15:02:26
来源:亿速云
阅读:532
作者:小新
mysql如何统计每个专业分数段的人数的呢?下面由亿速云小编给大家详细的介绍;
1.我的表结构student_info
| id |name |profession|score|
|–|–|–|–|
|id|姓名|分数|专业|
2.按分数段统计
400到500人数,300到400人数select
count(case when score between 400 and 500 then 1 end) as 400到500,
count(case when score between 300 and 400 then 1 end) as 300到400
from student_info;
3.按分数段和专业统计
400到500人数,300到400人数select
count(case when score between 400 and 500 then 1 end) as 400到500,
count(case when score between 300 and 400 then 1 end) as 300到400
from student_info GROUP BY profession;