product-sales-analysis-iii.sql (323B)
1 --Write a sql query to return the first year 2 --of each product that has been sold along with 3 --the quantity and price of that year. 4 5 SELECT s.product_id, s.year as first_year, s.quantity, s.price 6 FROM Sales s 7 WHERE (s.year, s.product_id) IN ( 8 SELECT MIN(s2.year), s2.product_id 9 FROM Sales s2 10 GROUP BY s2.product_id 11 )