Need to generate n rows based on a value in a column

后端 未结 6 871
闹比i
闹比i 2020-12-15 06:41

I have the following table

TABLE A

ID | QUANTITY
------------
1  | 3
2  | 2

What I need is

TABLE B

ID | Ref          


        
6条回答
  •  心在旅途
    2020-12-15 07:44

    This would also do the trick. It uses recursion, creates a table with rows 1-100.

    WITH NBR ( NUM ) AS (
        SELECT 1 UNION ALL
        SELECT 1 + NUM FROM NBR 
        WHERE NUM < 100
    )
    SELECT * into NUMBERS from NBR
    

提交回复
热议问题