select distinct(aq.com_code) spbm,aq.name name,aq.xz xz,round(sum(b.yssl/aq.xz),0) ztsl
      from str_rk_doc a,str_rk_com b,aqkc_bj aq
        where shbz='N'
        and a.seqno=b.seqno
        and a.shmc='000001'
        and aq.com_code=b.com_code
        group by aq.com_code,aq.name,aq.xz,b.yssl我想以aqkc_bj这个表为标准,从str_rk_com 表中查询数据,有则列出值,没有就为0,要如何做呀?

解决方案 »

  1.   

    select distinct(aq.com_code) spbm,aq.name name,aq.xz xz,round(sum(nvl(b.yssl,0)/aq.xz),0) ztsl
          from str_rk_doc a,str_rk_com b,aqkc_bj aq
            where shbz='N'
            and a.seqno=b.seqno
            and a.shmc='000001'
            and aq.com_code=b.com_code(+)
            group by aq.com_code,aq.name,aq.xz,b.yssl
      

  2.   

    tb1        tb2
    id  a      id   bselect a.a,nvl(b.b,0) as b
    from tb1 a, tb2 b
    where a.id=b.id(+)差不多就这个样子!