문제 해설
힌트
시도1 : 실패
/* Write your PL/SQL query statement below */
select product_id, first_year, quantity, price
from (
select a.product_id, a.year as first_year , a.quantity, a.price,
row_number() over (partition by a.product_id order by a.year) as rn
from Sales a
)
where rn = 1
왜일까.. output확인해보니 중복값이 있었다 . 그러므로 row_number를 쓰면 안됨.
정답
/* Write your PL/SQL query statement below */
select product_id, first_year, quantity, price
from (
select a.product_id, a.year as first_year , a.quantity, a.price,
rank() over (partition by a.product_id order by a.year) as rn
from Sales a
)
where rn = 1