From 06ebc44bb325e1a0eaf82d92c71ddf0383fb722b Mon Sep 17 00:00:00 2001 From: Kaaviya Varrshini Date: Sun, 1 Jun 2025 23:51:40 -0400 Subject: [PATCH] Completed MockSQL2 --- Problem1_CustomerProduct.sql | 8 ++++++++ Problem2_ProductAnalysis.sql | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 Problem1_CustomerProduct.sql create mode 100644 Problem2_ProductAnalysis.sql diff --git a/Problem1_CustomerProduct.sql b/Problem1_CustomerProduct.sql new file mode 100644 index 0000000..3c72456 --- /dev/null +++ b/Problem1_CustomerProduct.sql @@ -0,0 +1,8 @@ +# Write your MySQL query statement below + +select customer_id +#,count(distinct product_key) as productcount +from customer +group by customer_id +having count(distinct product_key) in (select count(product_key) +from product); \ No newline at end of file diff --git a/Problem2_ProductAnalysis.sql b/Problem2_ProductAnalysis.sql new file mode 100644 index 0000000..15b7b4a --- /dev/null +++ b/Problem2_ProductAnalysis.sql @@ -0,0 +1,10 @@ +# Write your MySQL query statement below +with cte as( +select product_id,min(year) as first_year +from sales +group by product_id) + +select s.product_id,c.first_year,s.quantity,s.price +from Sales s +inner join cte c on s.product_id=c.product_id +where s.product_id=c.product_id and s.year=c.first_year