by 조신부리 [SQL Query] 분석함수 LAST_VALUE FIRST_VALUE [2018.04.25 14:41:52]
안녕하세요.
with t as ( select 1 as id, 'txt1' as txt from dual union all select 2, '' from dual union all select 3, 'txt3' from dual union all select 4, '' from dual union all select 5, '' from dual union all select 6, 'txt6' from dual union all select 7, '' from dual union all select 8, '' from dual ) select id , txt , first_value(txt) over(order by id desc) txt2 from t order by id desc
가장큰 id의 txt값을 모든행에 표시함(txt가 null 이면 그이전값)==> 모든행에 txt6 로 반환함
with t as ( select 1 as id, 'txt1' as txt from dual union all select 2, '' from dual union all select 3, 'txt3' from dual union all select 4, '' from dual union all select 5, '' from dual union all select 6, 'txt6' from dual union all select 7, '' from dual union all select 8, '' from dual ) select id , txt , last_value(txt) ignore nulls over(order by id asc) txt2 from t order by id desc