SQL ✅ || Easy to Understand ✅ || GROUP BY, SUM, DISTINCT, SUBQUERY
Intuition\r\nWe can first group by customer_ids and then check them with having.\r\n\r\nThe pass shows 2 different ways to achieve the two solutions.\r\n\r\n\r\
# Intuition\r\nWe can first group by customer_ids and then check them with having.\r\n\r\nThe pass shows 2 different ways to achieve the two solutions.\r\n\r\n![image.png](https://assets.leetcode.com/users/images/8ebca5a0-4abf-40f7-b5e2-ea062298ee6a_1685536566.1817262.png)\r\n\r\n\r\n# First Solution\r\n```\r\nSELECT                                      \r\n    customer_id\r\nFROM Customer\r\nGROUP BY customer_id\r\nHAVING SUM(DISTINCT product_key) = (\r\n    SELECT\r\n        SUM(product_key)\r\n    FROM Product\r\n); \r\n```\r\n# Second Solution\r\n```\r\nselect \r\ncustomer_id\r\n#SubQuery Begin -->\r\nfrom (select \r\ncase \r\n     when count(distinct product_key) = (select count(product_key) from Product)\r\n         then  customer_id end as customer_id\r\nfrom Customer c\r\ngroup by customer_id)  as subquery\r\n# SubQuery --> End\r\nwhere customer_id is not null\r\n\r\n); \r\n```\r\n
['Database', 'MySQL']