Oracle: how to “group by” over a range?

后端 未结 10 1582
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 22:26

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

10条回答
  •  广开言路
    2020-12-07 23:23

    Can you try the below solution:

    SELECT count (1), '1-10'  where age between 1 and 10
    union all 
    SELECT count (1), '11-20'  where age between 11 and 20
    union all
    select count (1), '21+' where age >20
    from age 
    

提交回复
热议问题