출처
문제
모든 제품을 구매한 고객의 id를 출력하라
문제에 대한 해석
제품번호 5,6번을 모두 구매한 고객 1,3번을 출력하는 것
풀이(MYSQL)
방법1.
select customer_id
from Customer
group by customer_id
having group_concat(distinct(product_key) order by 1 ) = (select group_concat(product_key order by 1) from Product)
방법2.
select customer_id
from Customer
group by customer_id
having count(distinct( product_key)) = (select count(distinct(Product_key)) from Product)
'문제풀이 > SQL(My sql)' 카테고리의 다른 글
[문제풀이] Leet code - Sales Analysis III (0) | 2024.08.01 |
---|---|
[문제풀이] Leet code - Product Sales Analysis III (0) | 2024.08.01 |
[문제풀이] Leet code - Exchange Seats (0) | 2024.07.31 |
[문제풀이] Leet code - Friend Requests II: Who Has the Most Friends (0) | 2024.07.24 |
[문제풀이] Leet code - Average Selling Price (4) | 2024.07.23 |