100 % || EASY & INTUITIVE || SQL QUERY || ( Well - Defined ) || Using Sub - Query || Beats 96.92 %..
Intuition\n Describe your first thoughts on how to solve this problem. \nSELECT product_id, --> show the product_id from Sales table...\nyear AS first_year, -->
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSELECT product_id, --> show the product_id from Sales table...\nyear AS first_year, --> also show year alias as first_year...\nquantity, price --> also show quantity & price from Sales table...\nFROM Sales --> Association from Sales table...\nWHERE (product_id, year) IN --> Using sub - query for desire o/p...\n(SELECT product_id, --> as a sub - query show product_id...\nMIN(year) AS f_year --> Using Aggregation function MIN to find first year alias as f_year...\nFROM Sales --> Association...\nGROUP BY product_id); --> Grouping w.r.t. product_id (Aggregation)...\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing Fundamentals of SQL...\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nSELECT product_id, \nyear AS first_year, \nquantity, \nprice \nFROM Sales \n# ----SUB - QUERY----\nWHERE (product_id, year) IN \n(SELECT product_id, \nMIN(year) AS f_year \nFROM Sales \nGROUP BY product_id);\n```
['Database', 'MySQL']