34,838
社区成员




情况描述:
有一个表:如下
t
ID int 唯一记录标示
MediaID varchar(10) 媒体ID,
BusID int 站点ID,
Start datetime ,媒体使用开始时间
End datetime ,媒体使用结束时间
每个站点ID可以有几个媒体ID,每条记录的是的该媒体使用的时间段。
现在的问题是:
再某一个时间段内,媒体使用情况相对比较杂乱,想优化一下媒体的使用情况.
如:
ID MediaID BusID start end
1 'a' 1 '2008-01-01' '2008-01-15'
2 'b' 1 '2008-01-16' '2008-01-31'
3 'c' 1 '2008-02-01' '2008-02-29'
4 'a' 1 '2008-02-01' '2008-02-29'
以上记录可以看出在 '2008-01-01'到'2008-02-29'这个时间段内,
站点1,是可以被优化的,ID为2的记录,可以被优化成 MediaID 为'a'.
当然实际情况一个站点可以能有3个以上的媒体的。
我现在的情况是要处理多个媒体的情况下,我就不知道改如何处理这个优化记录了.
以下是测试数据
create table t
(
ID int identity(1,1) ,
MediaID varchar(10),
BusID int ,
start datetime ,
[end] datetime ,
status int , --记录是否被优化过
)
insert into t select 'a',1,'2007-12-01','2008-01-15',0
insert into t select 'a',1,'2008-02-16','2008-03-15',0
insert into t select 'a',1,'2008-05-01','2008-05-31',0
insert into t select 'b',1,'2008-01-16','2008-02-15',0
insert into t select 'b',1,'2008-04-01','2008-04-15',0
insert into t select 'c',1,'2007-12-16','2008-01-15',0
insert into t select 'c',1,'2008-03-16','2008-04-15',0
insert into t select 'd',1,'2008-01-01','2008-01-31',0
insert into t select 'd',1,'2008-03-01','2008-03-31',0
insert into t select 'e',1,'2008-01-01','2008-01-31',0
insert into t select 'f',1,'2008-02-16','2008-03-31',0
insert into t select 'g',1,'2008-05-01','2008-05-31',0
insert into t select 'h',1,'2008-02-01','2008-02-29',0
insert into t select 'i',1,'2008-04-01','2008-04-30',0
insert into t select 'j',1,'2008-02-01','2008-02-15',0
像以上记录:可以排列成
媒体 12月 12.5月 1月 1.5月 2月 2.5月 3月 3.5月 4月 4.5月 5月 5.5月 6月
a ———————————————————— —————————————— ——————————
b ———————————————— ————————
c —————————————— ——————————————
d —————————— ——————————
e ——————————
f —————————————————
g ————————————
h ————————————
i ——————————
j ——————
上图就是个媒体使用的时间段。
我现在被困扰的是在e媒体优化的时候可以选择f,g,h,i,j这个媒体。
可实际上这几个媒体都可以被安排到abcd中,所以e大致就不需要动了。
不知道我说明白了没有?脑袋乱了...