How to select Count of Ranges from mysql table?

I have a t_points table in mySql, as an example below.

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

I want to write a query that displays the number of point ranges. Point ranges look like this: a point from 0 to 100, 101 and 200, 201 and 300, 301 and 400. The result should be lower

0_100           101_200          201_300            301_400
3               5                4                  3

I think I understand what I want to say. So what query should I use for this result?
Thank.

+5
source share
5 answers
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
+11
source

Something like that:

select count(*) as count, abs(point/100) as range 
from t_poits
group by abs(point/100)
+1
source

. .

..

SELECT concat( 101 * round( Point /101 ) , '-', 101 * round( Point /101 ) +100 ) AS `range` , count( * ) AS `result`
FROM t_points
GROUP BY 1
ORDER BY Point

, .

+1

  set @range = 500;

select floor(field1/@range)*@range as `from`,(ceil(field1/@range)+if(mod(field1,@range)=0,1,0))*@range as `to`, count(field1)
from table1
group by 1,2
order by 1,2;
+1
select
    concat(floor(Point/100),'01_',ceil(Point/100),'00') as ind,
    count(*) as cnt
  from t group by ind order by ind asc;
0

All Articles