A라는 상품이 등급이 자주 변하는데요,
상품별 최초 변경일의 등급을 가져오고싶습니다.
예를 들어,
A 1일 1등급
A 2일 1등급
A 3일 1등급
A 4일 2등급
A 5일 2등급
A 6일 1등급
A 7일 1등급
A 8일 1등급
A 9일 3등급
위와 같다면,
1일 1등급
4일 2등급
6일 1등급
9일 3등급
이런식으로요!
RANK() OVER()를 쓰면 될것 같은데요 생각이 잘 안나고 급해서 질문드립니다!
LAG로 비교하면 어떨까요
with t (item, dt, lv) as ( select 'A', '1일', '1등급' from dual union all select 'A', '2일', '1등급' from dual union all select 'A', '3일', '1등급' from dual union all select 'A', '4일', '2등급' from dual union all select 'A', '5일', '2등급' from dual union all select 'A', '6일', '1등급' from dual union all select 'A', '7일', '1등급' from dual union all select 'A', '8일', '1등급' from dual union all select 'A', '9일', '3등급' from dual ) select dt, lv from ( select item, dt, lv, lag(lv,1,0) over (order by dt) lag from t ) where lv <> lag