-1

我正在尝试结合这些查询,但没有运气。我需要能够维护结果中的所有列。我怎样才能做到这一点?

这些是我的疑问:

SELECT c.CustomerID, EmailAddress, LastName, FirstName, Line1 AS BillLine1, Line2
       AS BillLine2, City AS BillCity, State AS BillState, ZipCode AS BillZip FROM 
       Customers c JOIN Addresses ON c.BillingAddressID = Addresses.AddressID 

SELECT Line1 AS ShipLine1, Line2 AS ShipLine2, City AS ShipCity, State AS ShipState,
       ZipCode AS ShipZip FROM Customers b JOIN Addresses ON b.ShippingAddressID = 
       Addresses.AddressID;
4

1 回答 1

3

也许是这样的?小号

ELECT
    c.CustomerID,
    EmailAddress,
    LastName,
    FirstName,
    a1.Line1 AS BillLine1,
    a1.Line2 AS BillLine2,
    a1.City AS BillCity,
    a1.State AS BillState,
    a1.ZipCode AS BillZip,
    a2.Line1 AS ShipLine1,
    a2.Line2 AS ShipLine2,
    a2.City AS ShipCity,
    a2.State AS ShipState,
    a2.ZipCode AS ShipZip
FROM
       Customers c
       JOIN Addresses a1 ON c.BillingAddressID = a1.AddressID
       JOIN Addresses a2 ON c.ShippingAddressID = a2.AddressID
于 2013-10-28T22:29:20.250 回答