Easy MySQL solution with explanation(Best for beginners)
Intuition\n Describe your first thoughts on how to solve this problem. \n- The question asks to retrieve the required columns for the first year of sale only.\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The question asks to retrieve the required columns for the first year of sale only.\n- For that, we write a sub-query which selects product_id and the first year of the product sale.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. In the SELECT statement, we retrieve the product_id, first_year, quantity and price.\n2. In the FROM statement, we write the table name Sales from which we retrieve the columns.\n3. The WHERE clause retrieves the product_id and MIN(year) as first_year and then uses GROUP BY clause to group the query by product_id.\n\n# Code\n```\n# Write your MySQL query statement below\nSELECT product_id, year as first_year, quantity, price \nFROM Sales \nWHERE (product_id, year) IN \n(\n    SELECT product_id, MIN(year) as year FROM Sales GROUP BY product_id\n)\n```\n# Note\nPlease upvote if you find my solution helpful. If you have any doubts, suggestion or want to discuss any solution, comment it. If you wish to discuss other related topics, feel free to message me on LinkedIn, https://leetcode.com/prathams29/
['MySQL']