Table:
new_table
user_number | diff
2 | 0
1 |
If you have regular ranges, a quicker solution would be to group with the help of div function.
For instance:
select diff div 20 as range, sum(user_number)
from new_table
group by diff div 20;
Ranges are represented as single digits in that case and you have to know what they mean: 0 = 0-19, 1 = 20-39, 2 = 40-59,...
If you need different ranges use different divider or maybe subtract some number from diff. For instance "(diff - 1) div 10" gives you ranges 1-10, 11-20, 21-30,...
You might want to check Are square brackets valid in an SQL query?
I suspect that '[' and ']' are used in Microsoft's SQL but not mysql.