I am trying to write a query that returns the count of items whose price falls into certrain buckets:
For example if my table is:
item_name | price
i1 | 2
i2 | 12
i3 | 4
i4 | 16
i5 | 6
output:
range | number of item
0 - 10 | 3
10 - 20 | 2
The way I am doing it so far is
SELECT count(*)
FROM my_table
Where price >=0
and price <10
then
SELECT count(*)
FROM my_table
Where price >=10
and price <20
and then copy pasting my results each time into excel.
Is there an automatic way to do this in an sql query?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…