日期:2014-05-18  浏览次数:20424 次

求SQL语句。
create   table   #A(idno   varchar(6),B   varchar(1),icdate   varchar(10),ictime   varchar(8))
insert   #A
select   '000008 ',T, '2007/9/26 ', '01:00:00 '   union   all                                          
select   '000008 ',T, '2007/9/26 ', '07:00:00 '   union   all                                       select   '000008 ',T, '2007/9/26 ', '12:30:00 '   union   all                                                                
select   '000008 ',T, '2007/9/26 ', '13:30:00 '   union   all
select   '000008 ',T, '2007/9/26 ', '17:00:00 '   union   all
select   '000008 ',T, '2007/9/27 ', '00:30:00 '   union   all

select   '000011 ',F, '2007/9/26 ', '13:00:00 '   union   all
select   '000011 ',F, '2007/9/26 ', '19:00:00 '   union   all
select   '000011 ',F, '2007/9/26 ', '23:00:00 '   union   all
select   '000011 ',F, '2007/9/27 ', '01:00:00 '   union   all
select   '000011 ',F, '2007/9/27 ', '07:00:00 '   union   all
select   '000011 ',F, '2007/9/27 ', '11:30:00 '   union   all


select   '000008 ',T, '2007/9/27 ', '07:30:00 '   union   all
select   '000008 ',T, '2007/9/27 ', '10:10:00 '   union   all
select   '000008 ',T, '2007/9/27 ', '12:30:00 '   union   all

select   '000011 ',F, '2007/9/27 ', '07:30:00 '   union   all
select   '000011 ',F, '2007/9/27 ', '10:10:00 '   union   all
select   '000011 ',F, '2007/9/27 ', '12:10:00 '   union   all

要得到结果,B   字段的值是确定的。   他决定了   时间的处理方式。

设X为日期     T白班         (X的1:00(包含1:00)到X+1的00:30:00(包含X+1的00:30:00))     跨度约23个半小时  
设X为日期     F晚班         (X的13:00(包含13:00)到X+1的12:30:00(包含X+1的12:30:00))   跨度约23个半小时

odno       icdate           T1   T2   T3   T4   T5   T6   T7   T8       八个固定时间字段  
000008   2007/9/26   01:00:00   07:00:00   12:30:00   13:30:00   17:00:00   00:30:00   NULL   NULL                  
000011   2007/9/26   13:00:00   19:00:00   23:00:00   01:00:00   07:00:00   07:30:00   10:10:00   11:30:00    
000008   2007/9/27   07:30:00   10:10:00   12:30:00     NULL           NULL             NULL           NULL         NULL

   
在结果中忽略   多于的