2 PostgreSQL solutions
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Code\n\npostgresql []\nSELECT \n    Sales.product_id as product_id,\n    Sales.year
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Code\n\n```postgresql []\nSELECT \n    Sales.product_id as product_id,\n    Sales.year as first_year,\n    Sales.quantity as quantity,\n    Sales.price as price\nFROM Sales\nJOIN (\n    SELECT product_id, MIN(year) AS first_year\n    FROM Sales\n    GROUP BY product_id\n) as Selftable  ON Sales.product_id = Selftable.product_id AND Sales.year = Selftable.first_year; \n```\n\n```\nSELECT \n    product_id,\n    year AS first_year,\n    quantity,\n    price\nFROM Sales\nWHERE (product_id, year) IN (\n    SELECT product_id, MIN(year)\n    FROM Sales\n    GROUP BY product_id\n);\n```\n\n![image.png](https://assets.leetcode.com/users/images/5f0a31a2-e8f6-44de-ac99-3f23a0f7e155_1730512900.6717477.png)\n
['PostgreSQL']