CAR | AMOUNT
---------------------
Ford | 5
---------------------
Peugeot | 7
---------------------
这是我的表,我希望在我的结果屏幕上看到5次"福特" 7次" Peugeot"
答案 0 :(得分:3)
WITH x AS
(
SELECT TOP (10) rn = ROW_NUMBER()
OVER (ORDER BY [object_id])
FROM sys.all_columns
ORDER BY [object_id]
)
--select * from x
SELECT car,AMOUNT
FROM x
CROSS JOIN #table2 AS d
WHERE x.rn <= d.AMOUNT
ORDER BY d.AMOUNT;
输出
car AMOUNT
Ford 5
Ford 5
Ford 5
Ford 5
Ford 5
Peugeot 7
Peugeot 7
Peugeot 7
Peugeot 7
Peugeot 7
Peugeot 7
Peugeot 7