我有一张包含以下数据的表格
Order_no | Part_No | R_from | R_to
1001 | 1010037-00L| 1 | 5
1001 | 1010025-00L| 6 | 12
我需要以下面的方式将上述数据提供给报告。
R_NO | PART_NO
------------------
1 | 1010037-00L
2 | 1010037-00L
3 | 1010037-00L
4 | 1010037-00L
5 | 1010037-00L
6 | 1010025-00L
7 | 1010025-00L
8 | 1010025-00L
9 | 1010025-00L
10 | 1010025-00L
11 | 1010025-00L
12 | 1010025-00L
答案 0 :(得分:0)
类似的东西:
WITH r_nos ( r_no ) AS (
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= ( SELECT MAX( R_to ) FROM your_table )
)
SELECT r_no,
part_no
FROM r_nos r
INNER JOIN
your_table y
ON ( r.r_no BETWEEN y.r_from AND y.r_to )
答案 1 :(得分:0)
这是一种不需要单独连接的替代方案。您应该测试两种解决方案,以确定哪种解决方案更适合您的数据等。
ID variable Date Balance
1: 1 1 01-01-2014 10000
2: 2 1 01-01-2015 50000
3: 3 1 01-08-2014 30000
4: 4 1 01-02-2016 5000
5: 1 2 01-02-2017 5000
6: 2 2 01-02-2016 30000
7: 3 2 01-02-2015 15000
8: 4 2 01-02-2018 3500