| 发表于:2007-09-26 16:39:033楼 得分:7 |
declare @t table(归属日期 varchar(20),班级 varchar(20), 学生 varchar(20),工作类别 varchar(20), 所用时间 int) insert @t select '9.1 ', '一 ' , 'a ', '擦桌子 ',8 union all select '9.1 ', '一 ' , 'b ', '拖地 ',7 union all select '9.1 ', '一 ' , 'c ', '拖地 ',6 union all select '9.1 ', '一 ' , 'd ', '擦桌子 ',5 union all select '9.1 ', '二 ' , 'e ', '拖地 ',4 union all select '9.1 ', '二 ' , 'f ', '拖地 ',5 union all select '9.1 ', '二 ' , 'g ', '拖地 ',6 union all select '9.1 ', '三 ' , 'h ', '擦桌子 ',10 union all select '9.1 ', '三 ' , 'i ', '擦窗户 ',9 union all select '9.1 ', '三 ' , 'j ', '擦窗户 ',8 union all select '9.1 ', '三 ' , 'k ', '拖地 ',7 union all select '9.1 ', '三 ' , 'l ', '擦桌子 ',6 union all select '9.1 ', '三 ' , 'm ', '擦桌子 ',5 union all select '9.1 ', '三 ' , 'n ', '拖地 ',4 select * from @t select 班级, 擦桌子=sum(case when 工作类别= '擦桌子 ' then 所用时间 else 0 end) , 擦窗户=sum(case when 工作类别= '擦窗户 ' then 所用时间 else 0 end) , 拖地 =sum(case when 工作类别= '拖地 ' then 所用时间 else 0 end), 合计 =sum(所用时间) from @t group by 班级 order by charindex(班级, '一,二,三 ') 测试结果 一 13 0 13 26 二 0 0 15 15 三 21 17 11 49 | | |
|