0

我目前正在 SQL 中创建一个查询,我需要在 Car For Sale 表中生成一个当前没有汽车销售的客户列表。到目前为止,我的代码如下:

SELECT 
  Customer.CustomerCode, CarForSale.CustomerCode
FROM 
  Customer LEFT JOIN CarForSale
  ON Customer.CustomerCode = CarForSale.CustomerCode
WHERE 
  CarForSale.CustomerCode IS NULL;

我遇到的问题是显示的正确客户代码不在 Car for Sale 表中,但是我需要将列标题显示为“CustomerCode”。

有谁知道我可以添加什么来制作这个?

4

2 回答 2

0
SELECT Customer.CustomerCode As [CustomerCode], CarForSale.CustomerCode
FROM Customer 
LEFT JOIN CarForSale ON Customer.CustomerCode = CarForSale.CustomerCode 
WHERE CarForSale.CustomerCode IS NULL

会工作。(如果使用 T-SQL)

于 2013-03-18T17:34:56.627 回答
0
SELECT
  *
FROM
(
SELECT 
  Customer.CustomerCode CustomerCodeA, CarForSale.CustomerCode CustomerCodeB
FROM 
  Customer LEFT JOIN CarForSale
  ON Customer.CustomerCode = CarForSale.CustomerCode
)
WHERE 
  CustomerCodeB IS NULL;
于 2013-03-18T17:35:52.997 回答