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