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; + +