select a.dq,sum(decode(b.tel,null,0,1))
 from area a,smsout b where dt<=sysdate and dt>sysdate-1 and a.dq=b.dq(+) group by a.dq;sum(decode(b.tel,null,0,1))
b.tel是空标记为0,非空为1,求和

解决方案 »

  1.   

    问题一:
    select dq,count(1) from smsout where trunc(dt)=trunc(sysdate) group by dq
    问题二:
    select a.dq,nvl(a.con,0) from (select dq,count(1) con from area group by dq) a,smsout b where trunc(a.dt)=trunc(sysdate) and a.dq(+)=b.dq
      

  2.   

    一个类似的例子(我的ORACLE 的版本也是8.1.7)
    select   b.name,nvl(sum(a.charge),0)
      from   report_acct_item a, acct_item_type b
     where   b.acct_item_type_id=a.acct_item_type_id(+)
     group by b.name
    我这里试就是可以的,没有的用0补充
      

  3.   

    按地区号统计手机号数量:
    select dq,val(count(tel),0) from smsout where dt<=sysdate and dt>sysdate-1 group by dq
    统计出来某些地区的手机号数量应该为0,但显示为空,并且该地区号也不显示.这是什么原因?这是因为没有满足条件dt<=sysdate and dt>sysdate-1的该地区记录。后面的SQL也是一样。除非你把它改写为select a.dq,nvl(count(b.tel),0) from area a,(select * from smsout  where dt<=sysdate and dt>sysdate-1) b
    where a.dq=b.dq(+) group by a.dq
      

  4.   

    非常感谢 Lastdrop(空杯) ,问题终于解决了,再次感谢