select sum(j.length),sum(d.length)
from (res_xl_gdgx x left join res_jkx_info j on j.ssgdgx = x.ssgdgx) left join res_dl_info d d.ssgdgx,0,21 =  x.ssgdgx 
where x.id = 'XIL0010494' group by x.Mc这样sum(d.length)的结果怎么不准呢。。该怎么写呢,各位帮帮忙!

解决方案 »

  1.   

    怎么个不准法?你试过不sum,然后贴到excel里面手动加一下吗?sum函数是系统内置的,应该不会不准确。
      

  2.   

    这样算的sum(d.length)的值是重复的
      

  3.   

    那应该是你的group by中少了对D表的某些列进行group by
      

  4.   

    先理解业务,然后就是表结构,再考虑如何写,我不知道你先统计什么,也不知道表结构,很难帮你找出问题。只能说你的语法应该没问题,我机上没有Oracle的
      

  5.   

    select x.mc, sum(j.length) from res_xl_gdgx x , res_jkx_info j where substr(j.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' group by x.Mc
    UNION 
    select x.mc, sum(d.length) from res_xl_gdgx x , res_dl_info d where substr(d.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' group by x.Mc最简单的方法
      

  6.   


    select mc,sum(length)length
    from (
    select x.mc, sum(j.length)length from res_xl_gdgx x , res_jkx_info j where substr(j.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' group by x.Mc
    UNION 
    select x.mc, sum(d.length)length from res_xl_gdgx x , res_dl_info d where substr(d.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' group by x.Mc) a 
    group by mc
      

  7.   

    这样的话是显示的是两个sum(length)之和,能让两个sum(length)分别显示吗?
      

  8.   

    select mc,sum(jlength)jlength,sum(dlength)dlength
    from (
    select x.mc, sum(j.length)jlength,0 dlength from res_xl_gdgx x , res_jkx_info j 
    where substr(j.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' 
    group by x.Mc
    UNION 
    select x.mc,0 jlength, sum(d.length)dlength from res_xl_gdgx x , res_dl_info d 
    where substr(d.ssgdgx,0,21) = x.ssgdgx || x.id and x.id = 'XIL0010494' 
    group by x.Mc
    ) a 
    group by mc