Solution using Sub-query and Window function
Intuition\n Describe your first thoughts on how to solve this problem. \nTo group the result set and identify the first record by year.\n# Approach\n Describe y
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo group the result set and identify the first record by year.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo group the data, window function is used, the first_value window function identifies the first_year partitioned by product_id, the outer query matches the year entry with the first_year to give the result.\n# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n-- Write your PostgreSQL query statement below\nselect product_id, first_year, quantity, price \nfrom\n(select product_id, year, quantity, price, \nfirst_value(year) over (partition by product_id order by product_id, year) as first_year\nfrom Sales) as subquery\nwhere year = first_year;\n```
['PostgreSQL']