gpt4 book ai didi

php - 如何将同一表中的多行连接成一行

转载 作者:行者123 更新时间:2023-11-30 23:16:47 25 4
gpt4 key购买 nike

我有这个问题。还请找到以下表格架构

http://sqlfiddle.com/#!2/36d20/14

SELECT
ca1.*,
ca2.*
FROM Contact_Address AS ca1
JOIN Contact_Address AS ca2
ON ca1.ca_contact_id = ca2.ca_contact_id
WHERE ca1.ca_contact_id = 1
AND ca1.ca_type = 'PRI'
AND ca2.ca_type = 'SEC'

我必须将同一表中包含的两行组合成一行。它们包含类型“PRI”、“SEC”。但条件是,对于一个用户,它将包含两行,而对于另一个用户,它将仅包含一个。

请帮忙,谢谢

最佳答案

SELECT
ca1.ca_contact_id as ci1,ca1.ca_type as type1,
ca2.ca_contact_id as ci2, ca2.ca_type as type2
FROM Contact_Address AS ca1
JOIN Contact_Address AS ca2
ON ca1.ca_contact_id = ca2.ca_contact_id
WHERE ca1.ca_contact_id = 1
AND ca1.ca_type = 'PRI'
AND ca2.ca_type = 'SEC'

SqlFiddle

你必须指定你的列名

关于php - 如何将同一表中的多行连接成一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17312577/

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