select 2z+2z2+z3+z4 as s_all

解决方案 »

  1.   

    select sum(z1),sum(z2),sum(z3),sum(z4),
           nvl(sum(z1),0)+ nvl(sum(z2),0)+ nvl(sum(z3),0)+ nvl(sum(z4),0) as sum_all
    from table
      

  2.   

    select DATE_NAME,SUM(nvl(sum(z1),0)+ nvl(sum(z2),0)+ nvl(sum(z3),0)+ nvl(sum(z4),0)) as sum_all
    from table
    GROUP BY DATE_NAME
      

  3.   

    但是z!里面求出来的和放在(sum(z1),0)里面会出错
      

  4.   

    没明白楼主想要的结果是什么,是这个?
    select z1,z2,z3,z4, z1+z2+z3+z4 z_all from tb
    union
    select sum(z1),sum(z2),sum(z3),sum(z4),sum(z1+z2+z3+z4) from tb
      

  5.   

    select s.oid,s.htmc,
    (select sum (z.jhje) from jh_ydzjjh z where z.ht_htgkoid=s.oid and z.nf like '2005'and z.yf like '12')as yfje,
    (select sum (t.sqzf) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.12')as ssqzfje,
    (select sum (t.jdkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.12')as jdkhk ,
    (select sum (t.zlkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.12')as zlkhk ,
    (select sum (t.aqwmkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.12')as aqwmkhk
    from ht_htgk s我就是想同时得到后面面4个字段的和
      

  6.   

    select s.oid,s.htmc,sum(z.jhje),sum(t.sqzf),sum(t.jdkhk),sum(t.zlkhk),sum(t.aqwmkhk),sum(t.sqzf+t.jdkhk+t.zlkhk+t.aqwmkhk)
    from ht_htsq t,ht_htgk s,jh_ydzjjh z 
    where t.ht_htgkoid=s.oid 
    and z.ht_htgkoid=s.oid
    and z.nf like '2004'and z.yf like '01'
    and to_char(t.zfq,'yyyy.mm') = '2005.12'
    group by s.oid,s.htmc
      

  7.   


    sum(t.sqzf+t.jdkhk+t.zlkhk+t.aqwmkhk)是有问题的,要保证sum中每个字段没有null值,因为1 + null +2 + 3 = null; 最好是sum(nvl(t.sqzf,0)...)
      

  8.   

    嗯,duanzilin(寻)说得对
    sum是做了判断的,不用加nvl,忘记了最后一个sum中是有'+'的,应该用nvl
      

  9.   

    select s.oid,s.htmc,
    (select sum (z.jhje) from jh_ydzjjh z where z.ht_htgkoid=s.oid and z.nf like '2005'and z.yf like '08')as yfje,
    (select sum (t.sqzf) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as sqzf,
    (select sum (t.jdkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as jdkhk ,
    (select sum (t.zlkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as zlkhk ,
    (select sum (t.aqwmkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as aqwmkhk,
    (select sum(t.sqzf+t.jdkhk+t.zlkhk+t.aqwmkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as zfje
    from ht_htgk s  当zfje为空时不显示这一行怎么写呀
      

  10.   

    ...where zfje is not null
      

  11.   

    不可以zfje不属于 ht_htgk这个表
      

  12.   

    楼主到底用那种方法啊?怎么写的还是老样子。这样写,可以
    select * 
    from (select s.oid,s.htmc,
    (select sum (z.jhje) from jh_ydzjjh z where z.ht_htgkoid=s.oid and z.nf like '2005'and z.yf like '08')as yfje,
    (select sum (t.sqzf) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as sqzf,
    (select sum (t.jdkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as jdkhk ,
    (select sum (t.zlkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as zlkhk ,
    (select sum (t.aqwmkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as aqwmkhk,
    (select sum(t.sqzf+t.jdkhk+t.zlkhk+t.aqwmkhk) from ht_htsq t where t.ht_htgkoid=s.oid and to_char(t.zfq,'yyyy.mm') like '2005.08')as zfje
    from ht_htgk s)
    where zfje is not null  
      

  13.   

    waterfirer(水清) 
    用你的方法