diff --git a/ Product Sales Analysis III.sql b/ Product Sales Analysis III.sql new file mode 100644 index 0000000..12b82cd --- /dev/null +++ b/ Product Sales Analysis III.sql @@ -0,0 +1,10 @@ +-- # Write your MySQL query statement below +-- select s1.product_id, s2.first_year, quantity, price +-- from Sales s1 join ( +-- select product_id, min(year) as first_year from Sales +-- group by product_id +-- ) s2 +-- on s1.product_id = s2.product_id and s1.year = s2.first_year + +select product_id, year as first_year, quantity, price from Sales +where (product_id, year) in (select product_id, min(year) as year from Sales group by product_id) \ No newline at end of file diff --git a/Customers Who Bought All Products.sql b/Customers Who Bought All Products.sql new file mode 100644 index 0000000..5c9b5c2 --- /dev/null +++ b/Customers Who Bought All Products.sql @@ -0,0 +1,4 @@ +SELECT customer_id +FROM Customer +GROUP BY customer_id +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(DISTINCT product_key) FROM Product) \ No newline at end of file