Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Alternative to Case Statement

$
0
0
I have a table in Oracle DB withe order count and unique IDs as columns:

Order Count ID
2 1
3 2
4 4
4 5
11 6
20 8
35 9
19 12
Now I want to get a count of IDs grouped by order and separated into different buckets. For e.g. all the orders that have value <= 10 ,I need to separate the order bucket by "1" and all the orders that have value >10 and <100 I need to separate the order bucket by 10.

The output for above table should be:
Count(ID) Order
1 2
1 3
2 4
3 11-20
0 21-30
1 31-40

I don't want to use case statement since I have a lot of such bucket based on which I need to group the data.

Please suggest how can I write the SQL query.

Viewing all articles
Browse latest Browse all 13329

Trending Articles