select x.员工ID,a.劳保用品ID,a.劳保用品名称
from
(select distinct 员工ID from b)x,a
where  a.劳保用品IDnot in(select 劳保用品IDfrom b where b.员工ID=x.员工ID)

解决方案 »

  1.   

    晕,空格没加select x.员工ID,a.劳保用品ID,a.劳保用品名称
    from
    (select distinct 员工ID from b)x,a
    where  a.劳保用品ID not in (select 劳保用品ID from b where b.员工ID=x.员工ID)
      

  2.   

    --创建调试环境
    if object_id('tbl_t') is null
    print 'not exists'
    else
    drop table tbl_t
    create table tbl_t
    (
    v_id varchar(20),
    v_nm varchar(20)
    )
    insert into tbl_t 
    select 
    '001'  ,    '口罩'
    union select
    '002'  ,    '洗衣粉'
    union select
    '003'  ,    '护目镜'
    union select
    '004'  ,    '防护鞋'
    create table tbl_t1
    (
    v_eid varchar(20),
    v_id varchar(20),
    v_nm varchar(20)
    )
    insert into tbl_t1 
    select 
    '1001' ,   '001'     ,     '口罩'
    union select
    '1001' ,   '002'     ,     '洗衣粉'
    union select
    '1002'  ,  '002'     ,     '洗衣粉'
    union select
    '1002'  ,  '003'     ,     '护目镜'
    select distinct t2.* from tbl_t1 t left join (select * from (select distinct v_eid from tbl_t1) t1 cross join tbl_t) t2 
    on t.v_eid=t2.v_eid and t.v_id<>t2.v_id where t2.v_id not in(select v_id from tbl_t1 where v_eid=t2.v_eid)select * from tbl_t a cross join tbl_t1 b on a.v_id<>b.v_id
    select 
    --删除表
    drop table tbl_t
    drop table tbl_t1--结果:
    /*
    v_eid                v_id                 v_nm                 
    -------------------- -------------------- -------------------- 
    1001                 003                  护目镜
    1001                 004                  防护鞋
    1002                 001                  口罩
    1002                 004                  防护鞋(所影响的行数为 4 行)
    */
      

  3.   


    select distinct b.v_eid,a.v_id,a.v_nm from tbl_t a cross join tbl_t1 b where a.v_id not in(select v_id from tbl_t1 where v_eid=b.v_eid)v_eid                v_id                 v_nm                 
    -------------------- -------------------- -------------------- 
    1001                 003                  护目镜
    1001                 004                  防护鞋
    1002                 001                  口罩
    1002                 004                  防护鞋(所影响的行数为 4 行)
      

  4.   

    select *
    from (select 员工id
            from b
        group by 员工id) t,a
    where not exists (select 1 from b where 员工id = t.员工id and 劳保用品id = a.id)
    order by 员工id
      

  5.   

    改自双规干部的
    select *
    from (select v_eid
            from tbl_t1
        group by v_eid) t,tbl_t
    where not exists (select 1 from tbl_t1 where v_eid = t.v_eid and v_id = tbl_t.v_id)
    order by v_eid
    结果;
    v_eid                v_id                 v_nm                 
    -------------------- -------------------- -------------------- 
    1001                 003                  护目镜
    1001                 004                  防护鞋
    1002                 001                  口罩
    1002                 004                  防护鞋(所影响的行数为 4 行)