select elt(interval(c.money, 0, 1000, 2000, 3000, 4000, 5000), 'less 1000', '1000to2000', '2000to3000', '3000to4000','4000to5000') as level, count(c.id) as cnt from (select sum(a.money) as money,b.id from 表1 as a,表2 as b where a.uid = b.id group by b.id) as c group by elt(interval(c.money, 0, 1000, 2000, 3000, 4000, 5000), 'less 1000', '1000to2000', '2000to3000', '3000to4000','4000to5000')
--------------
- select
- sum(
- case
- when examination_score between 90 and 100
- then 1 else 0
- end
- ) as 优秀,
- sum(
- case
- when examination_score between 80 and 90
- then 1 else 0
- end
- ) as 良好
- from el_test_info