✅ Oracle. MySQL Solution with CTE - Common Table Expression Approach
Intuition\n Describe your first thoughts on how to solve this problem. \nIn this query, a common table expression (CTE) first_year_sales is used to find the fir
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this query, a common table expression (CTE) first_year_sales is used to find the first year of sales for each product. Then we join this CTE with the Sales table to get the corresponding quantity and price information for the first year of each product.\n\n\n# Code\n```\n# Write your MySQL query statement below\n\nWITH first_year_sales AS (\n    SELECT \n        s.product_id,\n        MIN(s.year) AS first_year\n    FROM \n        Sales s\n    INNER JOIN \n        Product p ON p.product_id = s.product_id\n    GROUP BY \n        s.product_id\n)\n\nSELECT \n    f.product_id,\n    f.first_year,\n    s.quantity,\n    s.price\nFROM \n    first_year_sales f\nJOIN \n    Sales s ON f.product_id = s.product_id AND f.first_year = s.year\n\n```
['MySQL']