Simple Solution Using Rank Function
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem looks a bit on the moderate side if we do not use the rank function but as 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem looks a bit on the moderate side if we do not use the rank function but as soon as we rank the product id according to the year it will be easy to solve .\n\n---\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst thing to look is that we dont need the product table as we can see from the output example . \nsecond thing is that we have to modify the sales table on the basis of the rank pf the products on the basis of the product id \n```\nRANK() over (partition by product_id order by year) as rnk\nfrom sales\n```\nName this table as a seperate table to be used for the future use .\n```\nwith vi as \n(select * ,\nRANK() over (partition by product_id order by year) as rnk\nfrom sales)\n```\n\n---\n\n# Code\n```\n# Write your MySQL query statement below\n#30-12-2023\nwith vi as \n(select * ,\nRANK() over (partition by product_id order by year) as rnk\nfrom sales)\nselect product_id , year as first_year , quantity , price \nfrom vi where rnk = 1\n```
['Database', 'MySQL']