diff --git a/Problem1_CustomerProduct.sql b/Problem1_CustomerProduct.sql new file mode 100644 index 0000000..3c72456 --- /dev/null +++ b/Problem1_CustomerProduct.sql @@ -0,0 +1,8 @@ +# Write your MySQL query statement below + +select customer_id +#,count(distinct product_key) as productcount +from customer +group by customer_id +having count(distinct product_key) in (select count(product_key) +from product); \ No newline at end of file diff --git a/Problem2_ProductAnalysis.sql b/Problem2_ProductAnalysis.sql new file mode 100644 index 0000000..15b7b4a --- /dev/null +++ b/Problem2_ProductAnalysis.sql @@ -0,0 +1,10 @@ +# 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,c.first_year,s.quantity,s.price +from Sales s +inner join cte c on s.product_id=c.product_id +where s.product_id=c.product_id and s.year=c.first_year