我想找到那些尚未订购的客户。
我找到了一些查询以找到客户明智的总数。的订单,但无法查找/获取任何查询,这返回给我那些客户ID,而不是订单表。
也想按日期对结果进行排序,比如去年,去年等。
任何帮助/想法都将不胜感激。
谢谢!
答案 0 :(得分:6)
怎么样
SELECT c.*
FROM Customers c LEFT JOIN
Orders o ON c.CustomerID = o.CustomerID
WHERE o.CustomerID IS NULL
或
SELECT c.*
FROM Customers c
WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.CustomerID = c.CustomerID)
答案 1 :(得分:-1)
select c.* from Customers c
where c.CustomerID NOT IN (select o.CustomerID from Orders o)
答案 2 :(得分:-1)
select customer_name from customer
where customer_id not in (select customer_id from orders);