Repeat each value n times as rows in SQL

前端 未结 4 1620
盖世英雄少女心
盖世英雄少女心 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条回答
  •  一个人的身影
    2021-01-28 05:56

    You may use some temp table containing list of numbers 1 to N, where N is the highest number in your table names. Let call it num(o int) Then the query will be

    SELECT *
    FROM names, num
    WHERE num.o <= names.repeat
    

提交回复
热议问题