Programming/LeetCode
[LeetCode] Customers Who Never Order
데이터현
2022. 3. 31. 21:08
https://leetcode.com/problems/customers-who-never-order/
Customers Who Never Order - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
상품을 주문한 적 없는 회원을 찾는 문제
나의 풀이 - Left Join 활용
SELECT
Customers
FROM
(SELECT
name AS Customers, customerId
FROM Customers AS c LEFT JOIN Orders AS o
ON c.id = o.customerId
) AS m
WHERE customerId is NULL
;
----------------------------------------------
SELECT
Name AS 'Customers'
FROM Customers c LEFT JOIN Orders o
ON c.Id = o.CustomerId
WHERE o.CustomerId IS NULL
;
다른 풀이 - 서브쿼리 활용
select customers.name as 'Customers'
from customers
where customers.id not in
(
select customerid from orders
);
속도는 두 방법 거의 동일했다.