现在有一张表A,存放员工的打开记录,一张表B,记录每个月除了双休日的具体日期,现在想用两个表对比,查询出未打卡的员工名单,请大神帮忙解决下!
表A
1001 素娟 人事部 2014/10/9 08:43 18:16
1001 素娟 人事部 2014/10/10 08:56 18:16
1001 素娟 人事部 2014/10/14 08:55 18:18
1001 素娟 人事部 2014/10/15 08:50 18:16
1001 素娟 人事部 2014/10/16 08:49 18:16
1002 娟 人事部 2014/10/9 08:43 18:16
1002 娟 人事部 2014/10/10 08:56 18:16
1002 娟 人事部 2014/10/15 08:50 18:16
1002 娟 人事部 2014/10/16 08:49 18:16
...
表B
2014-10-06 16:37:54.007
2014-10-07 16:37:54.007
2014-10-08 16:37:54.007
2014-10-09 16:37:54.007
select
distinct a.name
from
(
select * from (select distinct name from a) as a cross join (select distinct times from a) as b
) as a
where not exists(select 1 from b where datediff(dd,times,a.times)=0)
有没有大神能帮忙看下,谢谢啦
表B干什么用的
另外无法知道所有员工。
你们是不是还应该有一个员工表啊?不然怎么知道所有的员工。
select
a.name
from
(
select * from (select dintinct name from a) as a cross join (select distinct times from a) as b
) as a
where not exists(select 1 from b where times=a.times)
--> 测试数据:[A]
if object_id('[A]') is not null drop table [A]
go
create table A,[dep] varchar(6),[times] datetime,[C5] datetime)
insert [A]
select 1001,'素娟','人事部','2014/10/9 08:43','18:16' union all
select 1001,'素娟','人事部','2014/10/10 08:56','18:16' union all
select 1001,'素娟','人事部','2014/10/14 08:55','18:18' union all
select 1001,'素娟','人事部','2014/10/15 08:50','18:16' union all
select 1001,'素娟','人事部','2014/10/16 08:49','18:16' union all
select 1002,'娟','人事部','2014/10/9 08:43','18:16' union all
select 1002,'娟','人事部','2014/10/10 08:56','18:16' union all
select 1002,'娟','人事部','2014/10/15 08:50','18:16' union all
select 1002,'娟','人事部','2014/10/16 08:49','18:16'
--> 测试数据:[B]
if object_id('[B]') is not null drop table [B]
go
create table B
insert [B]
select '2014-10-06 16:37:54.007' union all
select '2014-10-07 16:37:54.007' union all
select '2014-10-08 16:37:54.007' union all
select '2014-10-09 16:37:54.007'
--------------开始查询--------------------------
select
distinct a.name
from
(
select * from (select distinct name from a) as a cross join (select distinct times from a) as b
) as a
where not exists(select 1 from b where times=a.times)
----------------结果----------------------------
娟
素娟
(2 行受影响)
*/