高级SQL内容的新手。
想要这样做,以便select语句将填充值7次,然后移动到下一行。
实施例
X | Y
A 1
A 2
....
A 7
B 1
B 2
....
这是我的一些代码。
WHILE (*select that queries letters of unique value*) IS NOT NULL
BEGIN
INSERT INTO table1 (X,Y) *select that queries letters of unique value*,1
INSERT INTO table1 (X,Y) *select that queries letters of unique value*,2
....
INSERT INTO table1 (X,Y) *select that queries letters of unique value*,7
END
会喜欢一些帮助。谢谢!
答案 0 :(得分:0)
这是另一种方式:
SELECT *
FROM
(
SELECT 'A' AS VAL1
UNION
SELECT 'B'
) A
CROSS JOIN
(
SELECT 1 AS VAL2
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5
UNION
SELECT 6
UNION
SELECT 7
) B
ORDER BY A.VAL1
你也可以这样做:
CROSS JOIN
(
VALUES (1),(2),(3),(4),(5),(6),(7)
) B (VAL2)
ORDER BY A.VAL1
无需使用循环,您可以直接将这些值插入到表中,如:
INSERT INTO YourTable (X, Y)
SELECT A.VAL1, B.VAL2
FROM...