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를 구매한 것이다.
'코딩테스트 > SQL' 카테고리의 다른 글
[LeetCode][MySQL] Tree Node (0) | 2024.01.03 |
---|---|
[LeetCode][MySQL] Friend Requests II: Who Has the Most Friends (1) | 2024.01.03 |
[LeetCode][MySQL] Rearrange Products Table (0) | 2023.12.29 |
[LeetCode][MySQL] Group Sold Products By The Date (0) | 2023.12.20 |
[LeetCode][MySQL] Triangle Judgement (0) | 2023.12.13 |