# 문제
https://leetcode.com/problems/customers-who-bought-all-products/description/
# 문제 요약
Customer테이블에서 Product 테이블의 product_key들을 모두 산 customer_id 출력하기
# 핵심 개념
product_key들을 모두 샀는지 판단할때
Product테이블에서는 product_key가 기본키였기 때문에
select count(*) from Product로 전체 중복없는 개수를 알 수 있었다
from Customer에서 product_key는 기본키가 아니기 때문에 중복값이 나올 수 있다
따라서
count(*)
count(컬럼)
count(distinct 컬럼)중
count(distinct 컬럼)을 이용하면 중복없는 개수를 구할 수 있다
이 부분을
having count(distinct product_key) = (select count(*) from Product)
having에다가 사용하였다
# 정답 코드
select customer_id
from Customer
group by customer_id
having count(distinct product_key) = (select count(*) from Product)
# 앞으로의 다짐
sql문제를 복잡하게 생각하지 말고 매일매일 꾸준히 풀기
시간재고 풀어보기!!!