我在MysqL中有一个表t_points,如下例所示.
Name Surname Point
Joe Arnold 120
Michale Black 250
Masha Petrova 300
Natalie Jackson 120
John Turo 200
Bona Meseda 250
Zeyda Nura 150
Zanura Bohara 60
Shaheen Boz 360
Abbas Murat 160
Keira Black 230
Tom Robinson 480
Fred Balka 490
Semia Hudovi 90
Sona Bahari 60
我想写一个查询,它将显示点范围的计数.点范围是这样的:指向0到100之间,101和200,201和300,301和400.
结果必须如下
0_100 101_200 201_300 301_400
3 5 4 3
我想你明白我想说什么.那么我必须使用哪个查询来获得此结果?
谢谢.
最佳答案
select
count(CASE WHEN point BETWEEN 0 AND 100 THEN 1 END) as count0_100,count(CASE WHEN point BETWEEN 101 AND 200 THEN 1 END) as count101_200,count(CASE WHEN point BETWEEN 201 AND 300 THEN 1 END) as count201_300,...
from
t_poits