0

我正在尝试根据表中的一列中的值生成多行。我需要行数是列中数据值的三倍。目前我有它,所以它根据列中的值重复行数,但我不知道如何让它产生列中值的三倍。这是我的代码:

WITH tmp as (SELECT 1 as rn UNION ALL SELECT rn+1 from tmp WHERE rn<=1000)

    SELECT 
    [SURNAME],
    [NAME],
    [AGE],
    [PAYMENT DAYS PER/WK]

    FROM 
    [PublishedReporting].[dbo].[Sheet1$]
    LEFT JOIN (SELECT * FROM tmp WHERE rn<=50) as 
                                    rowgen on [PAYMENT DAYS PER/WK] >= rowgen.rn

    WHERE
    [PAYMENT DAYS PER/WK] IS NOT NULL

    ORDER BY
    SURNAME,
    NAME

    option (maxrecursion 32767);

这是我的结果示例:所以这里显示了露西亚当斯的 3 行,但我需要它显示 9

谢谢

4

2 回答 2

1
select * from  [PublishedReporting].[dbo].[Sheet1$]  
union all
select * from  [PublishedReporting].[dbo].[Sheet1$]  
union all
select * from  [PublishedReporting].[dbo].[Sheet1$]
order by 1;
于 2013-03-26T10:47:25.100 回答
0

作为说明,有一种替代方法通常不需要扫描表三次:

select t.*
from  [PublishedReporting].[dbo].[Sheet1$] t cross join
      (select 1 as n union all select 2 union all select 3) rows3
于 2013-03-26T14:04:18.863 回答