create table TaskList(
TaskID number(2),
ExeName varchar2(8),
StartTime date,
EndTime date);
insert into TaskList values( 1,'cmd ' ,to_date('2007/1/4 07:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 08:00','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 2,'notepad' ,to_date('2007/1/4 08:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 11:00','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 3,'exp' ,to_date('2007/1/4 08:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 13:30','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 4,'calc' ,to_date('2007/1/4 09:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 13:00','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 5,'excel' ,to_date('2007/1/4 09:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 15:30','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 6,'imp' ,to_date('2007/1/4 10:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 11:30','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 7,'sqlldr' ,to_date('2007/1/4 12:30','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 13:30','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 8,'sqlplus' ,to_date('2007/1/4 13:30','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 14:30','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values( 9,'sqlplusW',to_date('2007/1/4 18:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 19:00','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values(10,'telnet' ,to_date('2007/1/4 18:20','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 18:40','fmyyyy/mm/dd fmHH24:MI'));
insert into TaskList values(11,'tnsping' ,to_date('2007/1/4 20:00','fmyyyy/mm/dd fmHH24:MI')
,to_date('2007/1/4 21:00','fmyyyy/mm/dd fmHH24:MI'));
commit;
select a.TaskID,a.ExeName,
to_char(a.StartTime,'fmyyyy/mm/dd fmHH24:MI') as StartTime,
to_char(a.EndTime, 'fmyyyy/mm/dd fmHH24:MI') as EndTime,
max((select count(*) from TaskList c
where b.CheckTime between c.StartTime and c.EndTime)) as 最大多重度
from TaskList a,(select d.StartTime as CheckTime from TaskList d
union select d.EndTime from TaskList d) b
where b.CheckTime between a.StartTime and a.EndTime
group by a.TaskID,a.ExeName,
to_char(a.StartTime,'fmyyyy/mm/dd fmHH24:MI'),
to_char(a.EndTime, 'fmyyyy/mm/dd fmHH24:MI')
order by a.TaskID;