我想要一列數字: 整數1的7個發生,其次是7個發生2,然後是7個發生3 ....,然後是7個發生的n -1,然後是n的7次出現。像這樣遞歸cte重複幾個整數
Num
1
1
1
1
1
1
1
2
2
2
2
2
2
2
...
...
n-1
n-1
n-1
n-1
n-1
n-1
n-1
n
n
n
n
n
n
n
不幸的是我沒有太進步。我現在嘗試以下,其中n = 4:
WITH
one AS
(
SELECT num = 1,
cnt = 0
UNION ALL
SELECT num = num,
cnt = cnt + 1
FROM one
WHERE cnt < 7
),
x AS
(
SELECT num,
cnt = 0
FROM one
UNION ALL
SELECT num = num + 1,
cnt = cnt + 1
FROM one
WHERE cnt < 4
)
SELECT *
FROM x
檢查我的答案,是不是你所需要的? –