From 44dc0dd5d8dc639b1caa6d19ef469f9bf4056649 Mon Sep 17 00:00:00 2001 From: Sangeeth Santhosh <73825180+sangeeths29@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:46:50 -0700 Subject: [PATCH] Add files via upload --- 01-CustomersWhoBoughtAllProducts.sql | 8 ++++++++ 02-ProductSalesAnalysis-III.sql | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 01-CustomersWhoBoughtAllProducts.sql create mode 100644 02-ProductSalesAnalysis-III.sql diff --git a/01-CustomersWhoBoughtAllProducts.sql b/01-CustomersWhoBoughtAllProducts.sql new file mode 100644 index 0000000..ad93b29 --- /dev/null +++ b/01-CustomersWhoBoughtAllProducts.sql @@ -0,0 +1,8 @@ +-- Mock Interview Question 1 - Customers Who Bought All Products (https://leetcode.com/problems/customers-who-bought-all-products/) + +-- Selecting all the customer_id from the Customer Table where we are checking if the number of distinct product keys from both the customer and product table match + +SELECT customer_id +FROM Customer +GROUP BY customer_id +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(product_key) FROM Product); \ No newline at end of file diff --git a/02-ProductSalesAnalysis-III.sql b/02-ProductSalesAnalysis-III.sql new file mode 100644 index 0000000..4277ab2 --- /dev/null +++ b/02-ProductSalesAnalysis-III.sql @@ -0,0 +1,9 @@ +-- Mock Interview Question 2 - Product Sales Analysis III (https://leetcode.com/problems/product-sales-analysis-iii/) + +-- Writing an inner subquery for filtering minimum year and getting matching quantity and price for that year + +SELECT product_id, year AS first_year, quantity, price +FROM Sales +WHERE (product_id, year) IN (SELECT product_id, MIN(year) +FROM Sales +GROUP BY product_id); \ No newline at end of file