我现在查询出来的结果如下
id   xm    je         bh       
01   aa    23      20061012     
01   aa    30      20061013
01   aa    -23     20061012
01   aa    40      20061014现在这些记录中je和的值一个是正23一个是负23而bh是一致的
怎样能得到下面的结果
id   xm    je         bh        
01   aa    30      20061013
01   aa    40      20061014

解决方案 »

  1.   

    select * from (你写的select语句) b
    where bh not in 
    (
    select bh from (你写的select语句) a
    group by bh
    having sum(je)<>0
    )
      

  2.   

    select 
        t.* 
    from 
        表 t 
    where 
        not exists(select 1 from 表 where bh=t.bh and je=-t.je)
      

  3.   

    select substring(a.tmh,3,9) czyh,substring(c.brxm,0,6) cxm,c.brnl cnl,a.fyje mje,    
            d.szdm csfxmbm,substring(d.fymc,0,10) csfxm,    
            substring(a.cfbh,3,12) ccfh,b.fyrq dfy,a.fysl     
       from my_data.dbo.zysf_zyfymx a,my_data.dbo.ch_zyyf_zycfzb b,my_data.dbo.zysf_zydj c,    
            my_data.dbo.sys_kjsfxm d    
       where a.cfbh=b.cfbh and a.zyh=c.zyh and a.fydm=d.fydm and     
             a.zyh='0103200609050135' and a.cfbh<>''
      

  4.   

    select * from (你写的select语句) b
    where bh not in 
    (
    select bh from (你写的select语句) a
    group by bh
    having sum(je)<>0
    )
      

  5.   

    not exists语法不会用呀,上面是写的语句
      

  6.   

    select id,xm,sum(je) je ,bh from 结果 group by id,xm,bh having(sum(je)=0)
      

  7.   

    select 
        t.* 
    from 
        表 t 
    where 
        not exists(select 1 from 表 where bh=t.bh and je=-t.je)
      

  8.   

    select id, xm, sum(je), bh from (你的结果) group by id, xm, bh having sum(je) <> 0