基本需求如下:
假设员工人数1000人,只上白班,一个星期上6天,星期天休息,一天需要打3次卡,分别是07:00-08:00,12:00-13:00,17:00-18:00。考勤机中考勤的原始记录,我已经读取出来,现在问题是如何某人在某月中每天(除星期天)的某段时间(如07:00-08:00)没有打开记录,我怎样得到这个人没打卡记录的数据呢?
个人想法是先按人员的编号进行循环,再按日期进行循环,看指定时间段内是否有数据,但是如何按时间来循环的代码我不会写,请高手指点,我们查询的时间区间是以月为基准的。

解决方案 »

  1.   

    select * from 全体员工表 where 员工 not in (select 员工 from 考勤表 where ...)
      

  2.   

    你直接在数据库中
    sql语句解决问题
      

  3.   

    select ... from 员工信息表 a,考勤表 b where a.编号=b.编号 and a.编号 not in 
    (select 编号 from 考勤表 where ...时间段1...)
    union select ...
      

  4.   

    说一下思路不知道行不行~1.把你的员工表和考勤的原始记录做left out join关联~
    2.使用group by对员工的每天打卡进行分组~使用having得到打卡记录小于3的员工~
      

  5.   

    select t_num from employeeinf,note where employeeinf.t_num=note.t_num 
    and employeeinf.t_num not in(select t_num from note 
    where convert(char(7),t_notetime,120)='2008-12' 
    and convert(char(5),t_notetime,108) between '07:00' and '08:00')
    我按5楼的意见写了这条查询语句,但是提示t_num不明确??
    6楼的意见能不能说得再详细点,最好写个例子给我看一下,谢谢!
      

  6.   

    员工表 (员工编号,员工姓名)
    考勤表(员工编号,打卡时间)select *
    from 员工表
    where 员工编号 
    not in (select 员工编号 from 考勤表 where 打卡时间>='2009-01-20 07:00:00' AND 打卡时间<='2009-01-20 08:00:00')
      

  7.   

    把你昨天的那个结合了一下,得到一个可以查当日缺勤或者打卡不全的语句~~没测试。。select count(convert(char(10), t_notetime,120)),member.[id],convert(char(10),t_notetime,120) from
    (
    select min(t_notetime) as t_notetime,[人员ID] from noteinf where convert(char(10),cdate,120)='2009-01-21'
    and convert(char(5),t_notetime,108) between '07:00' and '08:00'
    group by [人员ID]
    union
    select min(t_notetime) as t_notetime,[人员ID] from noteinf where convert(char(10),cdate,120)='2009-01-21'
    and convert(char(5),t_notetime,108) between '12:00' and '13:00'
    group by [人员ID]
    union
    select min(t_notetime) as t_notetime,[人员ID] from noteinf where convert(char(10),cdate,120)='2009-01-21'
    and convert(char(5),t_notetime,108) between '17:00' and '18:00'
    group by [人员ID]
    )as kq
    right join member on [人员ID]=member.[id]
    group by member.[id],convert(char(10),t_notetime,120)
    having count(convert(char(10),t_notetime,120))<3