时间段的拆分
TEST_1 表:
BTIME ETIME CNAME
2011-10-13 12:23:45 2011-10-14 11:23:45 CCTV-1 B
SDINHOURS 表:
HOUR_ID STIME ETIME
24 00:00:00 00:59:59
1 01:00:00 01:59:59
. . .
. . .
. . .
. . .
24个小时
如何拆分 显示的结果为
2011-10-13 12:23:45 2011-10-13 12:59:59
。
。
。
2011-10-14 11:00:00 2011-10-14 11:23:45
就是以小时来拆分
------解决方案--------------------
我给你实验了一下,实际上可能只需要一个表:
create table test_1
(btime date,
etime date,
cname varchar2(100)
);
insert into test_1(btime,etime,cname) values('2011-10-13 12:23:45','2011-10-14 11:23:45','人大全程跟踪');
insert into test_1(btime,etime,cname) values('2011-10-09 10:05:20','2011-10-09 13:40:56','温布尔登网球公开赛直播');
commit;
select case when btime + (level - 1) / 24 > btime2 then btime + (level - 1) / 24 else btime2 end stime,
case when btime + level / 24 - 1 / 60 / 60 / 24 < etime2 then btime + level / 24 - 1 / 60 / 60 / 24 else etime2 end etime
from (select trunc(btime, 'hh24') btime,
btime btime2,
trunc(etime + 1 / 24, 'hh24') etime,
etime etime2
from test_1
where cname = '人大全程跟踪') t
connect by btime + level / 24 - 1 / 60 / 60 / 24 <=etime2 + 1/24 ;
但是,这个只能根据CNAME进行查询,可能需要你完善一下吧!