안녕하세요!
이번 포스팅은 LeetCode에 있는 Customers Who Bought All Products 문제를 OracleDB로 풀어보려고 합니다!
(모든 문제는 Oracle로 풀이하겠습니다.)
1. 문제 링크 : https://leetcode.com/problems/customers-who-bought-all-products/description/
2. 문제
| Column name | Type |
| customer_id | int |
| product_key | int |
[문제] Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.
제품 테이블의 모든 제품을 구입한 고객 테이블에서 고객 ID를 조회하는 문제입니다.
3. 제출 쿼리 및 설명
최종) 고객 별로 그룹화해서 상품의 전체 갯수와 한 명의 고객이 구입한 고유한 PRODUCT_KEY의 수가 같으면 제품 테이블에 있는 모든 제품을 구입한 고객입니다.
SELECT CUSTOMER_ID
FROM CUSTOMER
GROUP BY CUSTOMER_ID
HAVING COUNT(DISTINCT PRODUCT_KEY) = (SELECT COUNT(*)
FROM PRODUCT)
;
'SQL > LeetCode' 카테고리의 다른 글
| [SQL] Product Sales Analysis I(LeetCode/Oracle) (0) | 2023.10.19 |
|---|---|
| [SQL] Actors and Directors Who Cooperated At Least Three Times(LeetCode/Oracle) (0) | 2023.10.18 |
| [SQL] Swap Salary(LeetCode/Oracle) (0) | 2023.10.18 |
| [SQL] Exchange Seats(LeetCode/Oracle) (0) | 2023.10.18 |
| [SQL] Not Boring Movies(LeetCode/Oracle) (0) | 2023.10.18 |