안녕하세요. ^^. 새해 복 많이 받으세요. ^^
질문입니다.
한 컬럼에 데이터가 1,2,3, ......,9999,1,2,3, ......,8888,1,2,3, ......,9999 식으로 증가를 반복하는 데이터가 들어가 있습니다. (최대값은 달라집니다.)
with t1 as (
select '20191225000001' as 일자, 99 as 길이 from dual
union all select '20191225000002' , 100 from dual
union all select '20191225000003' , 200 from dual
union all select '20191225000004' , 300 from dual
union all select '20191225000005' , 400 from dual
union all select '20191225000006' , 500 from dual
union all select '20191225000007' , 600 from dual
union all select '20191225000008' , 10 from dual
union all select '20191225000009' , 20 from dual
union all select '20191225000010' , 30 from dual
union all select '20191225000011' , 40 from dual
)
이런 테이블이 있는데요. (실제로는 길이값이 증가하다가 줄어들고 다시 증가하고를 반복하는 테이블입니다. )
여기서 길이 값이 600인 데이터를 구해오고 싶습니다. 600의 값과 시간 정보를 어떻게 구할 수 있을까요. ?
with t1 as ( select '20191225000001' as 일자, 99 as 길이 from dual union all select '20191225000002' , 100 from dual union all select '20191225000003' , 200 from dual union all select '20191225000004' , 300 from dual union all select '20191225000005' , 400 from dual union all select '20191225000006' , 500 from dual union all select '20191225000007' , 600 from dual union all select '20191225000008' , 10 from dual union all select '20191225000009' , 20 from dual union all select '20191225000010' , 30 from dual union all select '20191225000011' , 40 from dual ) SELECT 일자, 길이 FROM ( SELECT 일자, 길이, LEAD(길이) OVER(ORDER BY 일자) 다음길이 FROM T1 ) WHERE 길이 > 다음길이