From 61cab57ce7a34c80f5250d3788b3493405498d25 Mon Sep 17 00:00:00 2001 From: Paneri Patel Date: Wed, 25 Jun 2025 15:57:25 -0400 Subject: [PATCH] Done Mock_SQL2 --- CustomersWhoBoughtAllProducts.sql | 8 ++++++++ ProductSalesAnalysisIII.sql | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 CustomersWhoBoughtAllProducts.sql create mode 100644 ProductSalesAnalysisIII.sql diff --git a/CustomersWhoBoughtAllProducts.sql b/CustomersWhoBoughtAllProducts.sql new file mode 100644 index 0000000..2f85519 --- /dev/null +++ b/CustomersWhoBoughtAllProducts.sql @@ -0,0 +1,8 @@ +''' +https://leetcode.com/problems/customers-who-bought-all-products/description/ +''' + +SELECT customer_id +FROM Customer +GROUP BY customer_id +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(*) FROM Product) \ No newline at end of file diff --git a/ProductSalesAnalysisIII.sql b/ProductSalesAnalysisIII.sql new file mode 100644 index 0000000..63be6e5 --- /dev/null +++ b/ProductSalesAnalysisIII.sql @@ -0,0 +1,11 @@ +''' +https://leetcode.com/problems/product-sales-analysis-iii/description/ +''' + +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