Oracle: how to "group by" over a range?

Posted by Mark Harrison on Stack Overflow See other posts from Stack Overflow or by Mark Harrison
Published on 2010-03-20T13:17:46Z Indexed on 2010/03/20 13:21 UTC
Read the original article Hit count: 195

Filed under:
|
|

If I have a table like this:

pkey   age
----   ---
   1     8
   2     5
   3    12
   4    12
   5    22

I can "group by" to get a count of each age.

select age,count(*) n from tbl group by age;
age  n
---  -
  5  1
  8  1
 12  2
 22  1

What query can I use to group by age ranges?

  age  n
-----  -
 1-10  2
11-20  2
20+    1

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about sql