I'm looking for a way to group results by ranges.
For example:
Data:
ID | Value
1 | 5
2 | 10
3 | 30
4 | 44
5 | 71
Result:
|From | To | Count(*) |
| 0 | 20 | 2 |
| 20 | 40 | 1 |
| 40 | 60 | 0 |
| 60 | 80 | 1 |
I know I could easily do this with a case or where query however I have several tables with an enormous variation in ranges (which also include decimal values) so I was hoping for a solution which would automatically create ranges of 20 in between the minimum and maximum values.
Two solutions which I have found but were unable to adapt:
group by price range (Very similar but it creates ranges from values so there will never be 0 ranges and doesn't do whole numbers)
Group rows by Year Band Interval (I'm not familiar with the use of floor but this is what I'm trying to accomplish, but I couldn't get it to accurately count the rows)
Thank you so much for your help
James