[Leet Code] Customers Who Never Order
+-------------+---------+
| 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 값은 ~~is null 이라 해야함 ( a = null x)
두 테이블에서 조인으로 입력할 부분 확실하게 알기
Author And Source
이 문제에 관하여([Leet Code] Customers Who Never Order), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@bohee0506/Leet-Code-Customers-Who-Never-Order저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)