Table:
new_table
user_number | diff
2 | 0
1 |
Here's a solution that will work for any magnitude of diff:
select
concat(21 * round(diff / 21), '-', 21 * round(diff / 21) + 20) as `range`,
count(*) as `number of users`
from new_table
group by 1
order by diff;
Here's some testable code and its output:
create table new_table (user_number int, diff int);
insert into new_table values (2, 0), (1, 28), (2, 32), (1, 40), (1, 53), (1, 59), (1, 101), (1, 105), (2, 108), (2, 129), (2, 130), (1, 144);
-- run query, output is:
+---------+-----------------+
| range | number of users |
+---------+-----------------+
| 0-20 | 1 |
| 21-41 | 1 |
| 42-62 | 2 |
| 63-83 | 2 |
| 105-125 | 3 |
| 126-146 | 2 |
| 147-167 | 1 |
+---------+-----------------+