How to unfold the results of an Oracle query based on the value of a column

后端 未结 4 1389
小蘑菇
小蘑菇 2020-12-04 00:58

I have a table on a Oracle DB with two columns. I would like to see every row repeated as many times as the number stored in the second column. The table looks like this:

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 01:46

    If a is your table then you can also do :

    select a1.col1 , a1.col2 
          from a a1
          join  (select level col2  from dual 
          connect by level < ( select max(col2) + 1 from a))   a2
          on a2.col2 between 1 and a1.col2
    

提交回复
热议问题