product 테이블에 있는 product key를 모두 구입한 customer 테이블의 customer_id를 구하는 문제
having절과 count 함수를 함께 사용해서 조건절을 만들었다.
select distinct customer_id
from customer
group by customer_id
having count(distinct product_key) = (select count(distinct product_key) from product)
'Data > SQL' 카테고리의 다른 글
[프로그래머스] FrontEnd 개발자 찾기 (1) | 2025.01.02 |
---|---|
[solvesql] 다음날도 서울숲의 미세먼지 농도는 나쁨 😢 (0) | 2024.02.24 |
[Leetcode] 175. Combine Two Tables, 178. Rank Scores, 184. Department Highest Salary (0) | 2024.01.15 |
[Leetcode] 1661. Average Time of Process per Machine (0) | 2024.01.09 |
[Leetcode] 602. Friend Requests II: Who Has the Most Friends (0) | 2024.01.09 |