From a59fbe149575d17fb7778d98997e36eaef3dba41 Mon Sep 17 00:00:00 2001 From: SAI NIHITH IMMANENI Date: Sat, 11 Jan 2025 10:03:20 -0600 Subject: [PATCH] Done Mock SQL2 --- Product Sales Analysis III.sql | 10 ++++++++++ Customers Who Bought All Products.sql | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 Product Sales Analysis III.sql create mode 100644 Customers Who Bought All Products.sql diff --git a/ Product Sales Analysis III.sql b/ Product Sales Analysis III.sql new file mode 100644 index 0000000..12b82cd --- /dev/null +++ b/ Product Sales Analysis III.sql @@ -0,0 +1,10 @@ +-- # Write your MySQL query statement below +-- select s1.product_id, s2.first_year, quantity, price +-- from Sales s1 join ( +-- select product_id, min(year) as first_year from Sales +-- group by product_id +-- ) s2 +-- on s1.product_id = s2.product_id and s1.year = s2.first_year + +select product_id, year as first_year, quantity, price from Sales +where (product_id, year) in (select product_id, min(year) as year from Sales group by product_id) \ No newline at end of file diff --git a/Customers Who Bought All Products.sql b/Customers Who Bought All Products.sql new file mode 100644 index 0000000..5c9b5c2 --- /dev/null +++ b/Customers Who Bought All Products.sql @@ -0,0 +1,4 @@ +SELECT customer_id +FROM Customer +GROUP BY customer_id +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(DISTINCT product_key) FROM Product) \ No newline at end of file