상품 별 첫 판매된 년도,양,가격을 출력하라
SELECT product_id
,year AS first_year
,quantity
,price
FROM Sales
WHERE (product_id,year) IN ( SELECT product_id
,MIN(year) AS year
FROM Sales
GROUP BY product_id
)
WITH min_year_table AS (
SELECT product_id, min(year) min_year
FROM sales
GROUP BY product_id)
SELECT s.product_id, s.year first_year, quantity, price
FROM sales s
JOIN min_year_table m ON s.product_id = m.product_id and s.year = m.min_year