Beats 97.63% | 2 Ways| CTE | Dense_Rank
\n\n# Code\n## First Way\n\n/* Write your T-SQL query statement below */\nWith cte as(\n select product_id, min(year) as first_year\n from Sales\n group by prod
\n\n# Code\n## First Way\n```\n/* Write your T-SQL query statement below */\nWith cte as(\n select product_id, min(year) as first_year\n from Sales\n group by product_id\n )\nselect cte.product_id, cte.first_year, quantity,price\nfrom cte join Sales on cte.product_id = Sales.product_id and cte.first_year=Sales.year\n\n```\n## Second Way\n```\n/* Write your T-SQL query statement below */\n\nwith cte as (\n select product_id,\n year AS first_year,\n quantity,\n price,\n dense_rank() over(partition by product_id order by year asc) as rk\nfrom sales\n)\nselect product_id,first_year, quantity, price\nfrom cte\nwhere rk = 1\n```
['MS SQL Server']