+-------------+---------+
|Column Name |Type|+-------------+---------+
| customer_id | int || product_key | int |+-------------+---------+
This table may contain duplicates rows.
customer_id isnotNULL.
product_key is a foreignkey (reference column) to Product table.
Table: Product
1
2
3
4
5
6
+-------------+---------+
|Column Name |Type|+-------------+---------+
| product_key | int |+-------------+---------+
product_key is the primarykey (columnwithuniquevalues) for this table.
Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.
Input:
Customer table:+-------------+-------------+| customer_id | product_key |+-------------+-------------+|1|5||2|6||3|5||3|6||1|6|+-------------+-------------+Product table:+-------------+| product_key |+-------------+|5||6|+-------------+Output:
+-------------+| customer_id |+-------------+|1||3|+-------------+Explanation:
The customers who bought all the products(5 and 6) are customers with IDs 1 and 3.
The key idea is to count, for each customer, how many unique products they have bought and compare it to the total number of products. If the counts match, the customer has bought all products.