yas
yas

Reputation: 3620

SQL to split Single row into multiple based on a count value?

I have an SQL statement that returns the following data:

FISCAL_ID    SECTION_ID      MAX_COUNT
1            1               3
1            2               1
2            1               2
2            2               2

How would I write SQL to return:

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

I am trying to generate a range of values for the max_count of each row in the data.

Upvotes: 1

Views: 609

Answers (1)

user5683823
user5683823

Reputation:

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;

Upvotes: 1

Related Questions