From 376f15a816a187c7722c009361a44b453bb4548a Mon Sep 17 00:00:00 2001 From: Bharath Vuppala Date: Wed, 1 Jan 2025 23:02:41 -0800 Subject: [PATCH] MockSQL2 completed --- Customers Who bought all products.sql | 5 +++++ Product Analysis iii.sql | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 Customers Who bought all products.sql create mode 100644 Product Analysis iii.sql diff --git a/Customers Who bought all products.sql b/Customers Who bought all products.sql new file mode 100644 index 0000000..e51f5ac --- /dev/null +++ b/Customers Who bought all products.sql @@ -0,0 +1,5 @@ +SELECT c.customer_id +FROM Customer c +LEFT JOIN product p ON c.product_key = p.product_key +GROUP BY c.customer_id +having COUNT(DISTINCT c.product_key) = (SELECT COUNT(p1.product_key) FROM product p1) diff --git a/Product Analysis iii.sql b/Product Analysis iii.sql new file mode 100644 index 0000000..a7d67f0 --- /dev/null +++ b/Product Analysis iii.sql @@ -0,0 +1,5 @@ + +select s1.product_id, s1.year as first_year, s1.quantity, s1.price + from sales s1 + where (s1.product_id, s1.year) in ( select s2.product_id, min(s2.year) + from sales s2 group by s2.product_id) \ No newline at end of file