조회에 모두 오라클 (11)와 Oracle (12)에 나를 위해 작동 알려 주시기 바랍니다 수 : 데이터의 4 개 행이 선택되었다는 것을
가
with data (start_date, end_date)
as (
select to_date('31-01-2014','dd-mm-yyyy') as start_date, to_date('05-02-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-12-2013','dd-mm-yyyy') as start_date, to_date('01-01-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-12-2013','dd-mm-yyyy') as start_date, to_date('01-05-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-10-2014','dd-mm-yyyy') as start_date, to_date('15-11-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('06-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('05-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('04-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('03-10-2014','dd-mm-yyyy') as end_date from dual
)
select start_date, end_date from data
where to_number(
end_date - (case when start_date > to_date('01-01-2014','dd-mm-yyyy')
then start_date
else to_date('01-01-2014','dd-mm-yyyy') end)
) > 4
"START_DATE" "END_DATE"
31-JAN-14 05-FEB-14
31-DEC-13 01-MAY-14
31-OCT-14 15-NOV-14
01-OCT-14 06-OCT-14
참고. 쿼리에 조건에 맞는 열을 추가하여 무슨 일이 벌어지고 있는지 확인하는 것이 좋습니다. 기준 값 표시하는 쿼리입니다 :
with data (start_date, end_date)
as (
select to_date('31-01-2014','dd-mm-yyyy') as start_date, to_date('05-02-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-12-2013','dd-mm-yyyy') as start_date, to_date('01-01-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-12-2013','dd-mm-yyyy') as start_date, to_date('01-05-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('31-10-2014','dd-mm-yyyy') as start_date, to_date('15-11-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('06-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('05-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('04-10-2014','dd-mm-yyyy') as end_date from dual
union all
select to_date('01-10-2014','dd-mm-yyyy') as start_date, to_date('03-10-2014','dd-mm-yyyy') as end_date from dual
)
select start_date, end_date,
to_number(
end_date - (case when start_date > to_date('01-01-2014','dd-mm-yyyy')
then start_date
else to_date('01-01-2014','dd-mm-yyyy') end)) as elapsed
from data
where to_number(
end_date - (case when start_date > to_date('01-01-2014','dd-mm-yyyy')
then start_date
else to_date('01-01-2014','dd-mm-yyyy') end)
) > 4
"START_DATE" "END_DATE" "ELAPSED"
31-JAN-14 05-FEB-14 5
31-DEC-13 01-MAY-14 120
31-OCT-14 15-NOV-14 15
01-OCT-14 06-OCT-14 5
반대의 기준이 일을 보장하기 위해, 나는이
where to_number(
end_date - (case when start_date > to_date('01-01-2014','dd-mm-yyyy')
then start_date
else to_date('01-01-2014','dd-mm-yyyy') end)
) <= 4
에 기준을 변경하고 다시이있어 :
"START_DATE" "END_DATE" "ELAPSED"
31-DEC-13 01-JAN-14 0
01-OCT-14 05-OCT-14 4
01-OCT-14 04-OCT-14 3
01-OCT-14 03-OCT-14 2
을