Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calc ranges in oracle

Tags:

sql

range

oracle

I have a table defining ranges, e.g.:

START | END | MAP
1     | 10  | A
11    | 15  | B
...

how do I query into that table so the result will be

ID | MAP
1  | A
2  | A
3  | A
4  | A
5  | A
6  | A
7  | A
8  | A
9  | A
10 | A
11 | B
12 | B
13 | B
14 | B
15 | B
...

I bet its a easy one... Thanks for the help

f.

like image 774
filippo Avatar asked Aug 27 '10 12:08

filippo


1 Answers

 select * from Table, (Select Level as Id from dual connect by Level <= (Select Max(End)      from Table)) t
 Where  t.Id between rr.Start and rr.End
 Order by Map, Start, Id
like image 101
Michael Pakhantsov Avatar answered Sep 19 '22 21:09

Michael Pakhantsov