[Leet Code] Customers Who Never Order

1259 ワード

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the ID and name of a customer.
Table: Orders
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| customerId | int |
+-------------+------+
id is the primary key column for this table.
customerId is a foreign key of the ID from the Customers table.
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.
Write an SQL query to report all customers who never order anything.
Return the result table in any order.
The query result format is in the following example.
[エラークエリ]
SELECT Customers.name FROM Customers
left join Orders on Customers.id=Orders.id
where Orders.customerID=NULL
[正解照会]

SELECT name as customers FROM Customers AS C
LEFT JOIN Orders AS O ON C.ID=O.CustomerID
where O.CustomerID is null 
せきぶん
クエリーの作成時にnull値は~~isnull(a=null x)でなければなりません.
2つのテーブルで結合入力として使用する部分を決定します.