1070. Product Sales Analysis III # best solution # beats 99.83%
Intuition\nWe can either solve using a min(year) or using windows function Rank\n\n# Approach\nHere I have assigned the rank to each record based on the year of
# Intuition\nWe can either solve using a min(year) or using windows function Rank\n\n# Approach\nHere I have assigned the rank to each record based on the year of the sales\n\n# Complexity\n- Time complexity:\n813ms\n\n- Space complexity:\n0B\n\n# Code\n```mysql []\n# Write your MySQL query statement below\nwith sale as \n(select *,rank() over (partition by product_id order by year) as rw\nfrom sales)\n\nselect product_id,year as first_year,quantity, price from sale\nwhere rw=1;\n\n\n```
['MySQL']