select count(*) from po.t_po_partmt t 
where t.invoiceno not in (select a.invoiceno from po.t_po_accpart a )
當然是0了,自己不在自己中的,當然是0

解决方案 »

  1.   

    当然会结果为0,如果每个invoiceno在整个po.t_po_accpart表中都有记录,那自然都不符合not in的条件啦
      

  2.   

    用这个可以找出来
    select count(*) from po.t_po_partmt t 
    where t.invoiceno not in 
    (select a.invoiceno from po.t_po_accpart a where t.invoiceno=a.invoiceno)
      

  3.   

    sorry:
    但還是沒有什么奇怪的地方啊。
    select count(*) from po.t_po_partmt t 
    where t.invoiceno in (select a.invoiceno from po.t_po_accpart a)
    结果是666.
    表名:t交a的記錄為666條select count(*) from po.t_po_partmt t 
    where t.invoiceno not in 
    (select a.invoiceno from po.t_po_accpart a where t.invoiceno=a.invoiceno)
    结果是248
    表名:t不在t交a中的記錄為248select count(*) from po.t_po_partmt t 
    where t.invoiceno not in (select a.invoiceno from po.t_po_accpart a )
    則是:t不在a中的記錄為0條-->t的所有記錄都在a中
    是很奇怪,應該是248條才對。
      

  4.   

    就是啊,
    select count(*) from po.t_po_partmt t 
    where t.invoiceno not in (select a.invoiceno from po.t_po_accpart a )
    这个想应该要返回的不是0是248,但是就是返回0。
    如果这样是返回248。
    select distinct t.invoiceno from po.t_po_partmt t
    minus
    select distinct t.invoiceno from po.t_po_partmt t, po.t_po_accpart a
    where t.invoiceno=a.invoiceno
    最上面的写到底错在哪里了呢
      

  5.   

    jiezhi(Niu) 再来指点,
    其他的高手们也出来啊,不要沉默啊!
      

  6.   

    是因为po.t_po_accpart 里面有: invoiceno is null的数据,当用t_po_partmt 和t_po_accpart 的数据比较时,遇到null就会返回0值。用exists 和not exists 可解决此问题。
      

  7.   

    select rownum,a.*,b.name,c.PARTNAME,c.PARTCODE,D.XM ,e.xm hxm,f.xm lxm,g.xm oxm,t.housename,c.stardard from t_po_accpart a, t_po_corplist b,t_po_part c,rdjbda d,  rdjbda e,rdjbda f,rdjbda g ,t_min_depotlist t  where  (a.flag='1' or a.flag='3' or a.flag='5' or a.flag='6')  and b.corpcode(+)=a.Pcode and a.PARTID=c.PARTID(+) and a.FAUDITBY=d.zgbh(+) and to_char(a.OCCURDATE,'yyyy-mm')='2003-09'and a.storeno=t.houseno(+) and a.handleby=e.zgbh(+)  and a.leader=f.zgbh(+) and a.operator=g.zgbh(+)  and (( a.accountflag is null and  a.invoiceno is not null) or (a.accountflag='3'  and  a.invoiceno is not null))  order by a.code desc
    这个能不能加快