我的查询结果中有多行:
例如,表“地址”:
Street | Number | City
----------------------
A1 | A2 | A3
B1 | B2 | B3
我真正想要的是:
Address1_Street | Address1_Number | Address1_City | Address2_Street | Address2_Number | Address2_City
------------------------------------------------------------------------------------------------------
A1 | A2 | A3 | B1 | B2 | B3
谁知道我怎么能做到这一点?
我现在已经做到了这一点(抱歉使用其他列,上面是一个例子,但我猜你会明白的):
select distinct
a.ID,
a.Name,
ca1.NameLine1 as Address1_NameLine1,
ca2.NameLine1 as Address2_NameLine1
from
dbo.Accounts a,
dbo.Addresses ca1,
dbo.Addresses ca2
where
(a.ID = ca1.AccountID AND a.ID = ca2.AccountID)
AND (a.Name = 'TEST')
AND (ca1.ID <> ca2.ID)
但我仍然得到 2 行......其中 Address1 与 Address2 切换。有谁知道如何只得到一个?谢谢!