我现在有考勤原始数据如下 employee clickdate, clicktime
001 2005-01-01 08:00
002 2005-01-01 08:11
001 2005-01-01 12:00
... ... ...现在我想按月生成如下报表 employee day1 day2 day3 ... day31
001 08:00 ... ... ... ...
001 12:00 ... ... ... ...
002 ... ... ... ... ... 但是让我想破头都没想到如何实现,请大伙帮忙想想办法
from
(
select 姓名,
[1月份] = sum(case month(日期) when 1 then 工作时间 else 0 end),
[2月份] = sum(case month(日期) when 2 then 工作时间 else 0 end),
[3月份] = sum(case month(日期) when 3 then 工作时间 else 0 end),
[4月份] = sum(case month(日期) when 4 then 工作时间 else 0 end),
[5月份] = sum(case month(日期) when 5 then 工作时间 else 0 end),
[6月份] = sum(case month(日期) when 6 then 工作时间 else 0 end),
[7月份] = sum(case month(日期) when 7 then 工作时间 else 0 end),
[8月份] = sum(case month(日期) when 8 then 工作时间 else 0 end),
[9月份] = sum(case month(日期) when 9 then 工作时间 else 0 end),
[10月份] = sum(case month(日期) when 10 then 工作时间 else 0 end),
[11月份] = sum(case month(日期) when 11 then 工作时间 else 0 end),
[12月份] = sum(case month(日期) when 12 then 工作时间 else 0 end),
[全年总计]=sum(工作时间)
from
(
select 姓名,工作时间,日期
from vw_所有工时表
where 三级签字='1' and year(日期)=@年份 and
姓名 in (select 姓名 from worker where 部门=@部门)
) as a
group by 姓名
) as b
left outer join worker c
on b.姓名=c.姓名
order by 机构名,部门名,b.姓名