我正在尝试显示与William
. 在我的customer
表格中,我将邮政编码作为zipCode
列。在我的city
表中,我的城市名称为cityName
.
表城市:
zipCode (PK) cityName, stateCode
表客户:
customerId (PK) customerName, customerAddress, zipCode (FK)
到目前为止我的查询...
SELECT
cu2.customerName AS 'Customer Name',
ci2.cityName AS 'City Name'
FROM
customer as cu
INNER JOIN
city as ci ON cu.zipCode = ci.zipCode
INNER JOIN
city as ci2 ON ci.cityName = ci2.cityName
INNER JOIN
customer as cu2 ON ci2.zipCode = cu2.zipCode
AND cu2.customerName <> cu.customerName
WHERE
cu2.customerName = 'William'
它没有显示任何结果,因为我认为当他所在的城市有另外两个邮政编码时,它只会检查威廉的邮政编码。他的号码是 91709,cityNAME 还有 91708 和 91710。我需要找到该 cityNAME 内的其他客户。