select * from db1..t1 where 姓名 not in(select 姓名 from db..t2 where 年份 like '2000%')

解决方案 »

  1.   

    select * from 库1..表1 a where not exists
    (select 1 from 库2..表2  where 姓名=a.姓名 and left(年份,4)='2000')
      

  2.   

    select * from 库1..表1 a
    where not exists(
    select * from 库2..表2
    where 姓名=a.姓名
    and 请假天数>0
    and 年月 like '2000年%')
      

  3.   

    select * from 库1.dbo.表1 where 姓名 not in 
    (select distinct 姓名 from 库2.dbo.表2 where convert (char (4),年份)='2000') a
      

  4.   

    select 姓名,编号 from (select a.*,b.年份 from db1..t1 a left join db2..t2 b on a.姓名=b.姓名 where  b.年份 like '2000%' )a where 年份 is null
      

  5.   

    create table ta(姓名 varchar(10),編號 varchar(5))
    Insert into ta
    select 'b','2'
    union all select 'c','9'
    union all select 'd','4'
    union all select 'e','5'
    union all select 'f','8'
    create table tb(姓名 varchar(10),請假天數  int,年份 varchar(100))
    Insert into tb 
    select 'a','1','1998年7月'
    union all select 'a','2','1999年7月'
    union all select 'b','1','2001年1月'
    union all select 'b','4','2000年2月'
    union all select 'b','5','2000年5月'
    union all select 'c','6','2000年5月'
    union all select 'd','7','2004年5月'
    select distinct b.姓名 from ta a inner join tb b on a.姓名=b.姓名 where  
    b.姓名 not in (select distinct  姓名 from tb where left(年份,4)='2000')(a)沒有在表1中出現過,(b,c)在2000年都有請假,所以結果應該是只有(d)沒有在2000年請假過
      

  6.   

    exists /not exists
    这两个换用一下就是请过假/没请过假的了,楼主自己也该动手
      

  7.   

    --1是 由表1和表2 找出2000年没有请过假的人select * from 库1..表1 a
    where not exists(
    select * from 库2..表2
    where 姓名=a.姓名
    and 请假天数>0
    and 年月 like '2000年%')
    --2是 由表1和表2 找出2000年请过假的人select * from 库1..表1 a
    where exists(
    select * from 库2..表2
    where 姓名=a.姓名
    and 请假天数>0
    and 年月 like '2000年%')
      

  8.   

    //2是 由表1和表2 找出2000年请过假的人select distinct b.姓名 from ta a inner join tb b on a.姓名=b.姓名 where  
    b.姓名  in (select distinct  姓名 from tb where left(年份,4)='2000')