Repeat each value n times as rows in SQL

前端 未结 4 1619
盖世英雄少女心
盖世英雄少女心 2021-01-28 05:36

I have been trying to achieve this in SQL (Oracle 11g) for a while but could not find a proper way to do it.

My table names has the following rows:

4条回答
  •  旧时难觅i
    2021-01-28 05:54

    Try this:

    select * from names
    cross join (select rownum n from dual
                connect by level <= (select max(repeat) from names))
    where n <= repeat
    order by name
    

提交回复
热议问题