很抱歉,如果在其他地方已经回答了这个问题,但如果有,我就找不到了。 我有一个表格,用于更改地址表格,其中包含许多地址的ID,CurrentAddressID和OldAddressID(必须为)和LandlordAddressID(可选)。
TableFormSubmissions
[Forename],
[Surname],
[Telephone],
[CurrentAddressID],
[OldAddressID],
[LandlordAddressID]
TableAddresses
[HouseNumber],
[Street],
[District],
[County],
[Postcode]
我想提出一个列出的视图:
Forename,
Surname,
Telephone,
HouseNumber (Current),
Street (Current),
District (Current),
County (Current),
Postcode (Current),
HouseNumber (Old),
Street (Old),
District (Old),
County (Old),
Postcode (Old),
HouseNumber (Landlord if provided),
Street (Landlord if provided),
District (Landlord if provided),
County (Landlord if provided),
Postcode (Landlord if provided)
我目前的SQL是乱七八糟的,不起作用,为了避免尴尬而省略了。 有人可以帮忙吗?
答案 0 :(得分:1)
如果我正确理解了问题
的
的SELECT
Forename,
Surname,
Telephone,
tsCurrent.HouseNumber [CurrentHouseNumber ],
tsCurrent.Street [CurrentStreet ],
tsCurrent.District [CurrentDistrict ],
tsCurrent.County [CurrentCounty ],
tsCurrent.Postcode [CurrentPostcode ],
tsOld.HouseNumber [OldHouseNumber ],
tsOld.Street [OldStreet ],
tsOld.District [OldDistrict ],
tsOld.County [OldCounty ],
tsOld.Postcode [OldPostcode ],
tsLandLord.HouseNumber [LandlordHouseNumber ],
tsLandLord.Street [LandlordStreet ],
tsLandLord.District [LandlordDistrict ],
tsLandLord.County [LandlordCounty ],
tsLandLord.Postcode [LandlordPostcode ]
FROM TableFormSubmissions AS tfs
left JOIN TableAddresses AS tsCurrent ON tfs.CurrentAddressID = tsCurrent.AddressID
left JOIN TableAddresses AS tsOld ON tfs.CurrentAddressID = tsOld.AddressID
left JOIN TableAddresses AS tsLandLord ON tfs.CurrentAddressID = tsLandLord.AddressID
的