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