문제풀이/SQL

leetcode / Customers Who Never Order

monawa 2023. 8. 14.
728x90

https://leetcode.com/problems/customers-who-never-order/

 

Customers Who Never Order - LeetCode

Can you solve this real interview question? Customers Who Never Order - Table: Customers +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | +-------------+---------+ In SQL, id is the primary key colu

leetcode.com

 

문제

 

Write a solution to find all customers who never order anything.

Return the result table in any order.

The result format is in the following example.

 

내풀이

select name as Customers 
from Customers c left outer join Orders o 
on c.id = o.customerId 
where o.id is null

고객테이블과 주문 테이블을 합치고 (이떄 주문수가 없는테이블을 원하므로 leftjoin을 사용후 

오더 테이블의 id가 null인 이름만 찾아준다

728x90

댓글