我想要一列数字: 整数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
检查我的答案,是不是你所需要的? –