Simple Solution with two line query
Please Upvote my solution, if you find it helpful ;)\n\n# Intuition\nTo find the customers who have bought all the products, we need to compare the distinct pro
## ***Please Upvote my solution, if you find it helpful ;)***\n\n# Intuition\nTo find the customers who have bought all the products, we need to compare the distinct products bought by each customer with the total number of products available. If the counts match, it means the customer has bought all the products.\n\n# Approach\n1. Select the customer_id from the Customer table.\n1. Group the results by customer_id.\n1. Apply a HAVING clause to filter out customers who have not bought all the products.\n1. In the HAVING clause, use ***COUNT(DISTINCT product_key)*** to count the number of distinct product keys for each customer.\n1. Compare this count with the total count of product keys in the Product table obtained through a subquery.\n1. If the counts match, it means the customer has bought all the products.\n# Complexity\n- Time complexity:\nThe time complexity of this solution depends on the size of the Customer and Product tables. Let\'s assume there are n customers and m products. The counting of distinct product keys for each customer takes $$O(n)$$ time, and the subquery to count the total number of products takes $$O(m)$$ time. Therefore, the overall time complexity can be approximated as $$O(n + m)$$.\n\n- Space complexity:\nThe space complexity of this solution is considered $$O(1)$$ or constant. It only requires a constant amount of additional space for storing intermediate results and the subquery. The space usage does not depend on the size of the input tables.\n\n# Code\n```\n# Write your MySQL query statement below\n\n\'SELECT  customer_id FROM Customer GROUP BY customer_id\nHAVING COUNT(distinct product_key) = (SELECT COUNT(product_key) FROM Product)\'\n```\n***Please Upvote my solution, if you find it helpful ;)***\n![6a87bc25-d70b-424f-9e60-7da6f345b82a_1673875931.8933976.jpeg](https://assets.leetcode.com/users/images/9b775724-1c6b-46bb-8e7b-5f6f8be29f1c_1686125409.4786477.jpeg)\n
['Database', 'MySQL']