select * from ht_htgk tselect s.oid,s.htmc,
(select sum (z.jhje) from jh_ndzjjh z where z.ht_htgkoid=s.oid and z.nf like '200%')as yfje,(select sum (t.sqzf)as s1 from ht_htsq t where t.ht_htgkoid=s.oid) z1,
(select sum (t.jdkhk)as s2 from ht_htsq t where t.ht_htgkoid=s.oid) z2 ,
(select sum (t.zlkhk)as s3 from ht_htsq t where t.ht_htgkoid=s.oid) z3 ,
(select sum (t.aqwmkhk)as s4 from ht_htsq t where t.ht_htgkoid=s.oid) z4from ht_htgk s
我要同时得到Z1,z2,z3,z4的和怎么办.

解决方案 »

  1.   

    select z1+z2+z3+z4
    不过没看明白你要干吗
      

  2.   

    只是想按时间查询得到z1,z2,z3,z4.同时再求得到他们和.
    我用了z1+z2+z3+z4这个也不行的
      

  3.   

    select s.oid,s.htmc,
    (select sum (z.jhje) from jh_ydzjjh z where z.ht_htgkoid=s.oid and z.nf like '2004'and z.yf like '01')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.   

    select s.oid,s.htmc,sum(z.jhje+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
      

  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 '08')as yfje,
    (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
    不过
    t.sqzf+t.jdkhk+t.zlkhk+t.aqwmkhk 这几个字段里面为空的话就不行了
      

  6.   

    select s.oid as soid,s.htmc as shtmc,
    (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 
    当最后一个字段为空时不显示这一行怎么写呀 
    各位大狭帮帮