表A:
    userid name
      1    张三
      2    李四
      3    王五
      4    赵六
      5    张三
表B:
    id userid  countdate
     1   2     2010-11-8
     2   3     2010-11-8
     3   4     2010-11-9
检索出userid在表A存在而表B不存在且countdate为指定日期的记录,即检索结果为:
b.userid,a.countdate
   1        
   5
表结构及目的描述:表A是用户名,表B是在每次用户登录时写入一条记录,然后统计每天没登录系统的员工

解决方案 »

  1.   

    select * from a wehre userid not in(select userid from b where countdate=指定时间)
      

  2.   

    既然B中不存在,所以countdate肯定为空
    select a.userid,'' as countdate
    from 表A a
    where not exists (select * from 表B b where a.userid=b.userid and b.countdate='你的指定日期')
      

  3.   

    SELECT b.userid,b.countdate FROM a 
    WHERE userid not in (SELECT userid FROM b WHERE countdate='2010-11-11') 
      

  4.   

    select t.userid,a.countdate from a left join (select * from b where countdate = 'xxxx') t on a.userid = t.userid where t.countdate is null 
      

  5.   

    且countdate为指定日期的记录
    这个条件好像没有什么用啊
      

  6.   

    select userid,'指定日期' from a
    where userid not in(select userid from b where countdate = '指定日期')其实指定日期不用在SQL中表达,因为是你要指定的日期,所以肯定是唯一的
      

  7.   

    SELECT b.userid,b.countdate FROM 表A a,表B b  
    WHERE userid not in (SELECT userid FROM b WHERE countdate='2010-11-11')
      

  8.   

    select a.userid,b.countdate from tb1 left join tb2 on tb1.userid<>tb2.userid where countdate='指定的日期'
      

  9.   

    这样写:select a.userid,a.name from a where not in(select b.userid from b where countdate ='datetime' and a.useid = b.userid)
      

  10.   


    create table #A
    (
    userid int not null identity(1,1) primary key,
    name varchar(20)
    )
    create table #B
    (
    id int not null identity(1,1) primary key,
    userid int not null,
    countdate datetime not null
    )insert #A(name) values
    ('zhangsan'),
    ('lisi'),
    ('wangwu'),
    ('zhaoliu'),
    ('zhangsan')insert #B(userid,countdate)
    values
    (2,'2010-11-08'),
    (3,'2010-11-08'),
    (4,'2010-11-09')select * from #A a
    where a.userid not in(select userid from #B)
    drop table #A
    drop table #Bthe result:
    1        zhangsan
    5        zhangsan
    符合了检索出userid在表A存在而表B不存在
    那你的答案是要countdate,这个字段在B表中