本人现在做很简单的考勤系统,数据采集是由指纹考勤机读取,存放到数据库表中
简单表结构如下:
id varchar(30) 序列号
empno varchar(30) 员工号
checkTime dataTime 打卡时间
我如果要做统计每个员工日打卡报表,应该怎么统计呢;
求思路或代码最好!显示数据为:员工  上下班时间
aa    2012-05-01 09:00--2012-05-01 17:30
aa    2012-05-02 09:00--2012-05-02 17:30
aa    2012-05-03 09:00--2012-05-03 17:30
aa    2012-05-04 09:00--2012-05-03 17:30

解决方案 »

  1.   


    --> 测试数据:[test]
    if object_id('[test]') is not null drop table [test]
    create table [test](
    [员工] varchar(2),
    [上下班时间] varchar(50)
    )
    insert [test]
    select 'aa','2012-05-01 09:00--2012-05-01 17:30' union all
    select 'aa','2012-05-02 09:00--2012-05-02 17:30' union all
    select 'aa','2012-05-03 09:00--2012-05-03 17:30' union all
    select 'aa','2012-05-04 09:00--2012-05-04 17:30'
    select [员工],DATEDIFF(HH,LEFT([上下班时间],16),RIGHT([上下班时间],16)) as [上下班时间]
    from test/*
    员工 上下班时间
    aa 8
    aa 8
    aa 8
    aa 8
    */
      

  2.   


    多谢。。
    我希望显示的数据是上下班的时间。不是统计工作了多少小时。。
    SELECT empno,MAX(checkTime),MIN(checkTime)
    FROM test
    GROUP BY empno ,CONVERT(VARCHAR(10),checkTime,120)
    3 2012-05-01 17:33:34.000 2012-05-01 08:37:43.000
    1 2012-05-02 13:35:00.000 2012-05-02 09:02:06.000
    2 2012-05-02 15:35:08.000 2012-05-02 09:00:00.000
    3 2012-05-02 16:35:15.000 2012-05-02 08:45:45.000
    1 2012-05-03 13:46:57.000 2012-05-03 13:46:57.000
      

  3.   

    再添一个功能:
    根据日期得出星期
    select a as 星期, getdate() as 日期
     from(select a='星期一',b=1 
      union all select '星期二',2 union all select '星期三',3
      union all select '星期四',4 union all select '星期五',5
      union all select '星期六',6 union all select '星期日',0 
     )a where b = (datepart(weekday,getdate())-1)
      

  4.   

    简化一下:
    select datename(weekday,getdate()) 星期,getdate() 日期