특정 기간 동안 겹치는 날짜가 있는 데이터 조회
특정기간과 겹치는 날짜가 하루라도 있는 데이터 조회
기준기간 : 2013.5.2 ~ 2013.5.10
시작일 종료일
날짜1 : 2013.05.01 2013.05.10
날짜2 : 2013.05.08 2013.05.20
날짜3 : 2013.04.20 2013.06.10
날짜4 : 2013.05.05 2013.05.08
with t as ( select to_date('20130501', 'YYYYMMDD') ST, to_date('20130510', 'YYYYMMDD') ed from dual union all select to_date('20130508', 'YYYYMMDD') ST, to_date('20130520', 'YYYYMMDD') ed from dual union all select to_date('20130420', 'YYYYMMDD') ST, to_date('20130610', 'YYYYMMDD') ed from dual union all select to_date('20130320', 'YYYYMMDD') ST, to_date('20130321', 'YYYYMMDD') ed from dual union all select to_date('20130511', 'YYYYMMDD') ST, to_date('20130512', 'YYYYMMDD') ed from dual union all select to_date('20130505', 'YYYYMMDD') ST, to_date('20130508', 'YYYYMMDD') ed from dual ) select * from t WHERE st <= :ed1 AND ed >= :st1 -- 내가 풀이한 방법(각각의 경우를 모두 계산) -- where ( to_date(:st1, 'YYYYMMDD') >= st and to_date(:st1, 'YYYYMMDD') <= ed ) -- or ( to_date(:st1, 'YYYYMMDD') <= st and to_date(:ed1, 'YYYYMMDD') >= ed ) -- or ( to_date(:ed1, 'YYYYMMDD') >= st and to_date(:ed1, 'YYYYMMDD') <= ed ) ;참고 사이트 : http://oracleclub.com/article/60240 http://oracleclub.com/article/45391
최신 댓글