我有一个返回以下数据的SQL语句:
FISCAL_ID SECTION_ID MAX_COUNT
1 1 3
1 2 1
2 1 2
2 2 2
我如何编写SQL来返回:
FISCAL_ID SECTION_ID VALUES
1 1 1
1 1 2
1 1 3
1 2 1
2 1 1
2 1 2
2 2 1
2 2 2
我正在尝试为数据中每行的max_count生成一系列值。
答案 0 :(得分:1)
select fiscal_id, section_id, level as value
from test_data
connect by level <= max_count
and fiscal_id = prior fiscal_id
and section_id = prior section_id
and prior sys_guid() is not null;