Where The Streets Have No Name

구간데이터를 단위별로 나열해서 보여주기 본문

Developement/DataBase

구간데이터를 단위별로 나열해서 보여주기

highheat 2012. 8. 17. 11:51

with tmp as

 (select 'a' as id,

         to_date('200305021120', 'yyyymmddhh24mi') as sdate,

         to_date('200305021300', 'yyyymmddhh24mi') as edate

    from dual

  union

  select 'b' as id,

         to_date('200305021300', 'yyyymmddhh24mi') as sdate,

         to_date('200305021400', 'yyyymmddhh24mi') as edate

    from dual)

select *

  from (select to_date('200305020000', 'yyyymmddhh24mi') +

               (level - 1) * 0.5 / 24 as s,

               to_date('200305020000', 'yyyymmddhh24mi') + level * 0.5 / 24 as e

          from dual

        connect by level <= 24 * 2) a,

       tmp b

 where a.s < b.edate

   and b.sdate < a.e

;