将from中的表改为
from 
  sf_shoufjl a,
  (select distinct ... from jf_tuibdf) b,
  yda_gongddw g

解决方案 »

  1.   

    是这样,b表中的两条记录都是要的,目前我的写法是因为有两条记录匹配,结果两条记录都重复sum了一次,我想要的不是只取一条记录的数据。
      

  2.   

    try:
    select jiryf,dianjdm,beiz,col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13 from (
    select  b.jiryf,b.dianjdm,b.beiz                   
                                     ,0 col1 
                                     ,0 col2 
                                     ,0 col3                
                                     ,nvl(sum(b.muldj),0)  col4
                                     ,nvl(sum(b.sanxjj),0) col5
                                     ,nvl(sum(b.chengsfj),0) col6 
                                     ,sum(decode(sign(b.litdf),1,b.litdf,0)) col7 
                                     ,sum(decode(sign(b.litdf),-1,b.litdf,0)) col8
                                     ,nvl(sum(b.jifrl),0)  col9
                                     ,nvl(sum(b.rongldf),0)  col10
                                     ,nvl(sum(b.jifxl),0) col11
                                     ,nvl(sum(b.xuldf),0) col12 
                                     ,''2'' col13
     ,rank() over(partition by b.jiryf,b.dianjdm,b.beiz order by b.jiryf,b.dianjdm,b.beiz)  rk
                         from  sf_shoufjl  a,jf_tuibdf  b,yda_gongddw  g    
                         where  g.cengcbm  like  :0  
                         and  a.gongddw  =  g.danwbh  
                         and  (g.shujtjfs  =  ''1''  or  g.shujtjfs  =  ''2'')  
                         and  a.rukfs  =  ''2''  and  a.shoufsj  >=  :1  and  a.shoufsj  <  :2  
                         and  b.huh  =  a.huh  
                         and  a.yingsje<>0  
                         and  b.jiryf  =  a.yuef                       and  b.chulbz  =  ''已入库''  
                         group  by  b.jiryf,b.dianjdm,b.beiz
    ) t where rk=1