본문 바로가기
코딩테스트/SQL

[LeetCode][MySQL] Customers Who Bought All Products

by 포뇨j 2024. 1. 5.

https://leetcode.com/problems/customers-who-bought-all-products/

 

Customers Who Bought All Products - LeetCode

Can you solve this real interview question? Customers Who Bought All Products - Table: Customer +-------------+---------+ | Column Name | Type | +-------------+---------+ | customer_id | int | | product_key | int | +-------------+---------+ This table may

leetcode.com

 

select customer_id
from customer
group by customer_id
having count(distinct product_key) = (select count(distinct product_key) from product)


product 테이블 상의 product 개수와

각 customer가 구매한 product 개수가 동일하면 모든 product를 구매한 것이다.