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.
I can give you a dirty solution. But please don't laugh at me :(
Join these two tables, your actual table and the DUMMY table. Just like this :
SELECT
DUMMY_ID
,MAP
FROMDUMMY
, (SELECTSTART
,END
,MAP
FROMACTUAL
) ASACTUAL
WHEREDUMMY_ID
BETWEENSTART
ANDEND
Note that given query above is MySQL. I didn't use Oracle for long time but sure you got the point.
This solution at first glance it looks complicated, but generally resolves any range. Solve problem with VALUEs which may be interfered with any other range.
Firstly create sample table and insert data:
Now data look like this:
Now create object type:
And also create PIPELINED FUNCTION:
Finally you can use simple query:
Or create and select it from view (if you want hide OBJECT implementation):
Based on this my article:
http://martin-mares.cz/2010/08/oracle-db-pipelined-function/
In
PostgreSQL
, you could just do:Update:
Tested on your sample data: