From 037e485a802f88d608b08defafddd568e4de7107 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Mon, 2 Jun 2025 10:52:01 -0400 Subject: [PATCH] feat: problem 1 and 2 added --- ...-1045-customer-who-bought-all-products.sql | 13 ++++++++++++ problem2-1070-Product-Sales-Analysis-III.sql | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 problem1-1045-customer-who-bought-all-products.sql create mode 100644 problem2-1070-Product-Sales-Analysis-III.sql diff --git a/problem1-1045-customer-who-bought-all-products.sql b/problem1-1045-customer-who-bought-all-products.sql new file mode 100644 index 0000000..7ea2a6b --- /dev/null +++ b/problem1-1045-customer-who-bought-all-products.sql @@ -0,0 +1,13 @@ +with customer_product_purchase as ( + select + customer_id, + count(distinct product_key) as cnt + from + customer + group by customer_id +) + +select customer_id +from + customer_product_purchase +where cnt = (select count(product_key) from product) diff --git a/problem2-1070-Product-Sales-Analysis-III.sql b/problem2-1070-Product-Sales-Analysis-III.sql new file mode 100644 index 0000000..1d83af6 --- /dev/null +++ b/problem2-1070-Product-Sales-Analysis-III.sql @@ -0,0 +1,21 @@ +with product_sale_year as ( + select + product_id, + year as first_year, + quantity, + price, + dense_rank() over ( + partition by product_id + order by year + ) as rnk + from + sales +) + +select + product_id, + first_year, + quantity, + price +from product_sale_year +where rnk = 1 \ No newline at end of file