A表:进货单号,验收仓库
b表:进货单号,品号,单位,数量
c表:品号,单位,仓库名称,数量
要求在a,b 表中找出品号,单位,仓库与c表的品号,单位,仓库不相同的数据来。(即找出在a,b表存在,而在c表中不存在的数据)如何用not exists或not in写查询select a表.验收仓库,b表.品号,b表.单位,b表.数量 from a表,b表 where A表.进货单号=b表.进货单号 and 进货单头表.进货单号=" & form1.单号.text & " not exits(select * from c表.品号=b表.品号,c表.单位=b表.单位,c表.仓库名称=a表.验收仓库)这样写有错,要咱改?access数据库
select a表.验收仓库,b表.品号,b表.单位,b表.数量 from a表,b表 where A表.进货单号=b表.进货单号 and 进货单头表.进货单号=" & me.单号.text & "主要是查出窗体内某单号的单据相关内容.

解决方案 »

  1.   

    select * from a表 a join b表 on a.进货单号=b.进货单号 where b.品号 not in (select 品号 from c表)
      

  2.   

    进货单头表就写成a表,我测试下,有用就给分.这些条件不要的,不然查不出是哪张单据了,A表.进货单号=b表.进货单号 and 进货单头表.进货单号=" & me.单号.text & "
      

  3.   

    select * from a,b where a.进货单号=b.进货单号 and b.品号 not in (select 品号 from c)
      

  4.   


    --测试数据
    create table #ta(进货单号 varchar(20),验收仓库 varchar(30))
    insert into #ta values('dh001','广州')
    insert into #ta values('dh002','深圳')
    insert into #ta values('dh003','东莞')
    insert into #ta values('dh004','珠海')create table #tb(进货单号 varchar(20),品号 varchar(20) ,单位 varchar(50) ,数量  int)
    insert into #tb values('dh001','ph01','单位a',12)
    insert into #tb values('dh002','ph02','单位c',5)
    insert into #tb values('dh003','ph03','单位b',20)
    insert into #tb values('dh004','ph04','单位a',4)create table #tc(品号 varchar(20) ,单位 varchar(50),仓库 varchar(30) ,数量  int)
    insert into #tc values('ph01','单位a','广州',12)
    insert into #tc values('ph02','单位c','深圳',5)
    insert into #tc values('ph03','单位b','东莞',20)
    select * from #ta a join #tb b on a.进货单号=b.进货单号 where b.品号 not in (select 品号 from #tc)drop table #ta
    drop table #tb
    drop table #tc
    --结果
    --      dh004  珠海 dh004 ph04 单位a 4
      

  5.   

    select b.品号,b.单位a.验收仓库
    from a表 as a
    left join b表 as b on a.进货单号=b.进货单号
    outer join c表 as c on a.验收仓库=c.仓库 and b.品名=c.品名 and b.单位=c.单位 --单位应该被量化成统一的单位,同一物品不应该按单位分笔记录
      

  6.   

    Set bb = New ADODB.Recordset
    bb.Open "select b.品号,b.单位,a.验收仓库 from lldj_jhdt as a left join lldj_jhds as b on a.进货单号=b.进货单号 and a.进货单号=" & Me.进货单号(1).Text & " outer join kccl_zk as c on a.验收仓库=c.仓库名称 and b.品号=c.品号 and b.单位=c.单位", a, adOpenKeyset, adLockPessimistic我只改了三个表名,提示语法错误,操作符丢失?应还要加一个a.进货单号=" & Me.进货单号(1).Text & ",不然不能从a及b表中找不到具体的数据出来,加这个进去后,提示语法错误,操作符丢失,"2147217900"
      

  7.   

    最终找出来的a,b两表中存在而c 不存在的数据,则用recordset记录集方式addnew把a,b表中的品号,单位,仓库新增进c表中相应字段中去.
      

  8.   

    A表和B表的合集 minus c 表
      

  9.   

    由于没有标识列,只能同时比较三个列的值才行:Select 验收仓库,单位,品号 From #ta inner join #tb on #ta.进货单号=#tb.进货单号 Where 验收仓库+单位+品号 not in(select  仓库+单位+品号 from #tc)
      

  10.   

    不行,access数据库哦.我改成这样也不行
    bb.Open "select a.验收仓库,a.品号,a.单位 from a表 inner JOIN b表 ON a表.进货单号=lldj_jhds.进货单号 and a表.进货单号='" & Me.进货单号(1).Text & "' where a表.验收仓库 and b表.品号 and b表.单位 not in(select c表.品号 and c表.单位 and c表.仓库名称 from c表)", a, adOpenKeyset, adLockPessimistic
    a表.进货单号='" & Me.进货单号(1).Text & "'这句一定要有,不然找不出是哪张单号来
      

  11.   


    select a.进货单号,a.验收仓库,b.品号,b.单位,b.数量
        from a inner join b on a.进货单号=b.进货单号
        where not exists (select * from c where 品号=a.品号
            and 单位=a.单位 and 仓库名称=a.验收仓库)
      

  12.   

    select a.进货单号,a.验收仓库,b.品号,b.单位,b.数量
        from a inner join b on a.进货单号=b.进货单号
        where not exists (select * from c where 品号=b.品号
            and 单位=b.单位 and 仓库名称=a.验收仓库)
      

  13.   

    思路:
    用LEFT OUTER JOIN。举例:
    M表:
    A      B     C
    a1     b1    c1
    a2     b2    c2
    a3     b3    c3
    N表:
    C      D
    c1     d1
    c2     d2
    c5     d3
    SELECT M.A AS X,M.B AS Y,M.C AS Z,N.C AS E,N.D AS F
    FROM M
    LEFT OUTER JOIN N
    ON M.C=N.C 
    结果是:
     
    X      Y     Z      E      F
    a1     b1    c1     c1     d1
    a2     b2    c2     c2     d2
    a3     b3    c3     null   null
    再写一个Select,查询E,F字段是null的记录就行了
      

  14.   

    上面都少了a表.进货单号='" & Me.进货单号(1).Text & "'这句一定要有,不然找不出是具体的哪张单号的内容来,但如把这句用and 加到a.进货单号=b.进货单号
    后,好象是join方式不支持.困惑中,三张表关联,要筛选只得到a,b表中指向的具体单号内容中(品号,单位,仓库同时)在c表中没有相应字段(品号,单位,仓库同时)数据中不存在.