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