低级问题

select   'H00088' as 工号,	
         '张家栋' as 姓名,	
         '2011-06-01' as 开始日期	,
         '2011-06-16' as 结束日期,
         0 as 总工时	,
         '休息天数:3天' as 记事   into #t  union  
select   'H00088',	'张家栋',	'2011-06-01',	'2011-06-16',	38.1	,'异常天数:9天' union
select 'H00088'	,'张家栋',	'2011-06-01',	'2011-06-16'	,44.57	,'正常天数:4天' union
select 'H00224'	,'梁小春',	'2011-06-01',	'2011-06-16',	0	,'休息天数:2天' union
select 'H00224'	,'梁小春'	,'2011-06-01',	'2011-06-16'	,35.15,	'异常天数:11天' union
select 'H00224'	,'梁小春'	,'2011-06-01',	'2011-06-16'	,35.11	,'正常天数:3天'

 
-- drop  table #t
 

select 工号,姓名,开始日期,结束日期, sum(总工时) as  总工时,max(休息记事) +' '+max(正常记事)  +' '+max(异常记事) as 记事 from  
(
select 工号,姓名,开始日期,结束日期,总工时 ,
case  when  left(记事,2)='休息 ' then  记事 else  '' end 休息记事,
case  when  left(记事,2)='正常 ' then  记事 else  '' end 正常记事,
case  when  left(记事,2)='异常 ' then  记事 else  '' end 异常记事
from  #t 
)  re
group by  工号,姓名,开始日期,结束日期  


/*
H00088	张家栋	2011-06-01	2011-06-16	0	休息天数:3天
H00088	张家栋	2011-06-01	2011-06-16	38.1	异常天数:9天
H00088	张家栋	2011-06-01	2011-06-16	44.57	正常天数:4天

H00088 张家栋 2011-06-01 2011-06-16 82.67 休息天数:3天 异常天数:9天 正常天数:4天


*/


 

posted @ 2011-06-16 15:33  qanholas  阅读(326)  评论(0编辑  收藏  举报