我现在有考勤原始数据如下 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       ...   ...  ...   ...  ... 但是让我想破头都没想到如何实现,请大伙帮忙想想办法

解决方案 »

  1.   

    看SQL版面,有相关问题和回答,我忘了是哪个了
      

  2.   

    这个用存储过程做是比较方便的...你可以在Ms SQL版里Search一下.有相关的文章...
      

  3.   

    还有一个条件是数据库是access
      

  4.   

    我写的一个关于工时的交叉表,给你参考一下。select c.机构 as 机构名,c.部门 as 部门名,b.*
    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.姓名