gpt4 book ai didi

SQL(简单)逐行连接两个表

转载 作者:行者123 更新时间:2023-11-29 12:09:39 25 4
gpt4 key购买 nike

我想逐行加入 2 个表,这意味着如果我有两个表 A,B 我想要: A 的第 1 行仅加入 B 的第 1 行 A 的第 2 行仅加入 B 的第 2 行等

如果我有

table A
name

John
George
Nick
Legolas



table B
surname

Smith
Rogueman
Born
Yohazol


the result would be:

table C
name surname


John Smith
George Rogueman
Nick Born
Legolas Yohazol

提前致谢

最佳答案

像这样的..

SELECT *
FROM (
SELECT row_number() OVER (), *
FROM tbl1
-- ORDER BY id (or whatever you're ordering by)
) AS t1
INNER JOIN (
SELECT row_number() OVER (), *
FROM tbl2
-- ORDER BY id (or whatever you're ordering by)
) AS t2
USING (row_number);

关于SQL(简单)逐行连接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43334603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com