客戶這裏是我的表:發現誰沒有買從許多東西一對多的關係
Customers:
- CustomerId
- Name
- Address
- ContactNumber
ProductOrders:
-PorderKey
-CustomerId
-ProductId
Product:
-ProductId
-ProductName
-ProductDescription
是否有可能找到誰沒有買任何東西的客戶?如果是的話我應該如何設計我的查詢?
客戶這裏是我的表:發現誰沒有買從許多東西一對多的關係
Customers:
- CustomerId
- Name
- Address
- ContactNumber
ProductOrders:
-PorderKey
-CustomerId
-ProductId
Product:
-ProductId
-ProductName
-ProductDescription
是否有可能找到誰沒有買任何東西的客戶?如果是的話我應該如何設計我的查詢?
NOT IN
或NOT EXISTS
你想要做什麼:
select c.*
from customers c
where c.customerid not in (select po.customerid from productorders po);
Ohhhh好的,謝謝! –
SELECT DISTINCT列,我,其實,要從first_table X LEFT JOIN lookup_table是開y.first_table_id = x.id WHERE y.some_not_nullable_column IS NULL
請分享你到目前爲止嘗試過的。 – 1000111
讓我添加更多信息。 –