LeetCode - 1045. Customers Who Bought All Products (MySQL)

조민수·2024년 6월 9일
0

LeetCode

목록 보기
26/61

Medium, SQL - GROUP BY, HAVING

RunTime : 468 ms


문제

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

Return the result table in any order.

The result format is in the following example.


풀이

  • 생각보다 매우 간단했던 문제
  • 개수 비교를 통해 해결할 수 있다.
SELECT customer_id FROM Customer
GROUP BY 1
HAVING COUNT(DISTINCT product_key) = (
    SELECT COUNT(product_key) FROM Product
)
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글