Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 01-CustomersWhoBoughtAllProducts.sql
Original file line number Diff line number Diff line change
@@ -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);
9 changes: 9 additions & 0 deletions 02-ProductSalesAnalysis-III.sql
Original file line number Diff line number Diff line change
@@ -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);