From cef9c8512ca7c9ab0fa93833bd722c6ff8534c2b Mon Sep 17 00:00:00 2001 From: Sakshi Asati Date: Sat, 7 Jun 2025 19:22:00 -0600 Subject: [PATCH] Done Mock_SQL2 --- customers-who-bought-all-products.sql | 4 ++++ product-sales-analysis-iii.sql | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 customers-who-bought-all-products.sql create mode 100644 product-sales-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..b4c3384 --- /dev/null +++ b/customers-who-bought-all-products.sql @@ -0,0 +1,4 @@ +# Write your MySQL query statement below +select customer_id +From (select customer_id , count(distinct(product_key)) as cnt +from customer group by customer_id) as s where cnt = (select count(*) from Product); diff --git a/product-sales-analysis-iii.sql b/product-sales-analysis-iii.sql new file mode 100644 index 0000000..8a6eb3b --- /dev/null +++ b/product-sales-analysis-iii.sql @@ -0,0 +1,8 @@ +# 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, s.year as 'first_year', s.quantity, s.price from Sales s +join cte on cte.first_year=s.year and cte.product_id=s.product_id; + +