'问题:考勤表出现了没有打卡的人员,那么如何用SQL语句来判断没有打卡的人员呢?(如何得到没有打卡的人员和日期).
''各自为两个数据表:'一个表是: "员工表" 字段: "编号" "姓名" '001 小麦
'002 小王'另一个表是: "考勤表" 字段: "卡号" "日期" "打卡时间" '001 01 08:28
'001 01 12:01
'001 01 13:01
'001 01 18:00 '002 01 08:28
'002 01 12:01
'002 01 13:01
'002 01 18:00
'001 02 08:28
'001 02 12:01
'001 02 13:01
'001 02 18:00 '说明:编号为002的在02日没有打卡
select '001', '小麦' union
select '002', '小王'
insert into t2(no,kdate,ktime)
select '001','01',' 08:28' union
select '001','01',' 12:01' union
select '001','01',' 13:01' union
select '001','01',' 18:28' union
select '002','01',' 08:28' union
select '002','01',' 12:01' union
select '002','01',' 13:01' union
select '002','01',' 18:28' union
select '001','02',' 08:28' union
select '001','02',' 12:01' union
select '001','02',' 13:01' union
select '001','02',' 18:28'
--这种方法比较直接
select *,'01' from [t1] where not exists(
select 1 from [T2] where t1.no=t2.[No] and t2.[Kdate] ='01') union
select *,'02' from [t1] where not exists(
select 1 from [T2] where t1.no=t2.[No] and t2.[Kdate] ='02')
drop table t1
drop table t2
建一个表做为专门判断的表,使用前后都清空数据,表的列是011,012,013,014,021,022,023,024,031,032,033,034,30天就是30*4=120列
分别代表01日的四个卡,02日的四个卡,03日的四个卡。。(Access不能写存储过程就是麻烦)
然后从你的第二个表中读取一行,判断卡号如果不存在就新增一行,然后把打卡时间写入相应的列,如果卡号存在就更新打卡时间到相应的列,当然对打卡时间要做一个判断以便写入相应的列,这样全部写一遍之后就可以根据Null值来判断哪个人哪天(甚至是哪个打卡时间)没有打卡。
如上午9:00为1,中午12:30为2;下午13:30为3,18:30为4.
select 卡号 from 考勤表 where 日期='01' group by 卡号,日期 having count(时间)<规定次数
第二步:再查询哪个时间没打卡
where 日期=查询日期 这样不是每次要来给个日期来判断.如果能 where 月份=查询月份 就能OK了.让判断查询的月份中没有打卡的人员.
select distinct 日期 from 考勤表得到本月某员工有考勤日期:
select distinct 日期 from 考勤表 where 卡号=某卡号查询本月某员工没有考勤的日期:
select distinct 日期 from 考勤表
union
select distinct 日期 from 考勤表 where 卡号=某卡号
select e.编号,f.姓名,e.日期
from (select 编号,日期
from (select a.编号,b.日期
from (select 编号 from 员工表) a
,(select 日期 from 考勤表 group by 日期) b
)
where 编号 & 日期 not in (select 编号 & 日期 from 考勤表 group by 编号, 日期)
) e
,员工表 f
where e.编号 = f.编号
2 要有加班表说明临时加班的情况。
3 要有请假表,说明请假的日期,时间和事由。
4 要有节假日表,说明节假日的调整情况。
5 如果是工业企业,还要有换休表。
6 ...对一个员工做当月考勤,首先要逐日循环,如果是他的工作日,或有加班,则搜索他在当天的打卡记录。如果没有记录,查请假表。如果是请假,汇总到请假中;否则按缺勤记录。如果有记录,对得到的每一个记录都要与上下班时间和加班时间比对,得出正常上班、迟到、早退和正常下班等结论。并计算工时。其中还有跨午夜的问题,也要根据考勤制度来处理。所以,实际上是逐人、逐日、逐记录分析的过程。在这个过程中,可以用 SQL 查询来加快进程,但不可能用几个查询来解决考勤统计的所有规则解释。