https://leetcode.com/problems/customers-who-never-order/
상품을 주문한 적 없는 회원을 찾는 문제
나의 풀이 - 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
);
속도는 두 방법 거의 동일했다.
'Programming > LeetCode' 카테고리의 다른 글
[LeetCode] Valid Palindrome II (0) | 2022.04.02 |
---|---|
[LeetCode] Department Highest Salary (0) | 2022.03.31 |
[LeetCode] Duplicate Emails (0) | 2022.03.31 |
[LeetCode] Employees Earning More Than Their Managers (0) | 2022.03.31 |
[LeetCode] Consecutive Numbers (MySQL) (0) | 2022.03.31 |
댓글