gpt4 book ai didi

SQL 简单连接,我很难过

转载 作者:行者123 更新时间:2023-12-04 20:31:38 25 4
gpt4 key购买 nike

我有一个带列的表:

JOB_NUM, HM_PH, BUS_PH, CALL1ST

其中 job_num 是唯一编号
HM_PHBUS_PHCALL1ST 列是 10 位电话号码

因此,使用上面的列顺序,示例数据将如下所示:
JOB_NUM, HM_PH,      BUS_PH,     CALL1ST
------------------------------------
12345, 4025557848, 9165897588, 7518884455
10101, 8887776655, 8667416895, 5558884446

我想要生产的是 2 列。
JOB_NUM, PHONE

job_num 列在每个电话号码旁边的位置,例如:
JOB_NUM PHONE
---------------------
12345 4025557848
12345 9165897588
12345 7518884455
10101 8887776655
10101 8667416895
10101 5558884446

我从哪里开始?

最佳答案

你需要一个 UNION(如果你想删除重复的行)或 UNION ALL(如果你想保留重复的行):

SELECT JOB_NUM, HM_PH AS PHONE FROM yourtable
UNION
SELECT JOB_NUM, BUS_PH FROM yourtable
UNION
SELECT JOB_NUM, CALL1ST FROM yourtable
ORDER BY JOB_NUM

关于SQL 简单连接,我很难过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3374428/

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