I have an int
field in my table scores
. It can be a number between 0 and 100. There are over a 1000 rows in that table. I want to select the number of rows that fall between ranges 0-25, 26-50, 51-75 and 76-100.
So basically, if this is my scores
table
score (int)
------------
10
20
12
56
43
90
87
The output of the query should look like this ( let's call the ranges R1, R2, R3, R4 )
R1 R2 R3 R4
------------------
3 1 1 2
Let me know if something's not clear.
EDIT I got this far
SELECT CASE score
WHEN score BETWEEN 0 AND 25 THEN 'R1'
WHEN score BETWEEN 26 AND 50 THEN 'R2'
WHEN score BETWEEN 51 AND 75 THEN 'R3'
ELSE 'R4'
END, COUNT(*)
FROM scores
But when I put a AS range
after END, I get an error. (UPDATE: nvm this, it supposed to be AS 'range', with quotes)
Also, if score is 0, it shows up under R2 and not R1. Why is that?