Challenge: Finding Customers Who Bought Everything
Difficulty: Medium
Data:
Two tables store information about customer purchases:
Customer (Primary Key: customer_id):
customer_id (int): Unique identifier for a customer.
product_key (int): Foreign key referencing the Product table (product purchased).
Product (Primary Key: product_key):
product_key (int): Unique identifier for a product.
Objective:
Identify customer IDs from the Customer table who have purchased all products listed in the Product table.
Output:
A table with a single column:
customer_id (int): Unique identifier for a customer who bought all products (same as input table).
Explanation:
We need to find customer_id values in the Customer table where the distinct count of product_key matches the total number of unique products in the Product table. This indicates customers who purchased every product.
SQL MYSQL leetcode Solution with HAVING and DISTINCT COUNT
Watch video Customers Who Bought All Products SQL MySQL leetcode Solution using having online, duration hours minute second in high quality that is uploaded to the channel CodeWis Technologies by Nuhman Paramban 20 May 2024. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 113 times and liked it 0 visitors.