日期:2014-05-18  浏览次数:20548 次

问题咨询,救助
我的数据是每天上班出入时的打卡记录,
 
UserAccount             enterdate

001                           2006.09.08
002                           2006.09.08
001                           2006.09.09
002                           2006.09.09
003                           2006.09.09
.
.
.
如上,2006.09.08   到   2006.09.09     编号为003的人   ,在2006.09.09   那天没有数据,就是他那天缺席了,

请问怎么写语句,找出哪个工号的人哪天没有数据?就是怎么找出003,在2006.09.09没有数据的?

在线等,谢谢

------解决方案--------------------
create table T(UserAccount varchar(10), enterdate datetime)
insert T select '001 ', '2006-09-08 '
union all select '002 ', '2006-09-08 '
union all select '001 ', '2006-09-09 '
union all select '002 ', '2006-09-09 '
union all select '003 ', '2006-09-09 '

select tmp.* from
(
select * from

(select distinct UserAccount from T) A,
(select distinct enterdate from T) B
where 1=1
)
tmp left join T on tmp.UserAccount=T.UserAccount and tmp.enterdate=T.enterdate
where T.UserAccount is null

--result
UserAccount enterdate
----------- ------------------------------------------------------
003 2006-09-08 00:00:00.000

(1 row(s) affected)