From f154d6e9e9cdb8435ef79a03779209c3de76d093 Mon Sep 17 00:00:00 2001 From: Rosaline Date: Tue, 31 Dec 2024 17:24:54 -0800 Subject: [PATCH] mock sql2 first commit --- Customers_who_bought_all_products.sql | 2 ++ Product_sales_analysis_iii.sql | 4 ++++ 2 files changed, 6 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..e9068e1 --- /dev/null +++ b/Customers_who_bought_all_products.sql @@ -0,0 +1,2 @@ +--Write your MySQL query statement below +select customer_id from customer group by customer_id having count(distinct product_key) = (select count(product_key) from product); \ No newline at end of file diff --git a/Product_sales_analysis_iii.sql b/Product_sales_analysis_iii.sql new file mode 100644 index 0000000..8c7f7a3 --- /dev/null +++ b/Product_sales_analysis_iii.sql @@ -0,0 +1,4 @@ +--Write your MySQL query statement below +with cte as (select distinct product_id , min(year) over (partition by product_id) as 'first_year' from sales ) +select s.product_id, s.year as 'first_year', s.quantity, s.price from sales s inner join cte c on c.product_id = s.product_id and s.year = c.first_year +