表中有字段 区域,子区域,完成,未完成 字段
现在要查询每个子区域下完成总数,未完成总数,完成率 这个语句该怎么写
拙计了,求大神支招
在线等

解决方案 »

  1.   

    遇到的问题是使用count统计了完成,未完成数量后却不能和表的group by 区域匹配
    select region,subregion,count(select * from comm_host_tbl where done='Y'),count(select * from comm_host_tbl where undone='Y') from comm_host_tbl group by region,subregion以上是我写的语句
      

  2.   


    select region,
           subregion,
           sum(decode(done,'Y',1,0)),
           sum(decode(undone,'Y',1,0)),
           sum(decode(done,'Y',1,0))/((sum(decode(undone,'Y',1,0))/ sum(decode(done,'Y',1,0)))
      from comm_host_tbl
     group by region, subregion
      

  3.   


    sum(decode(done,'Y',1,0))/(sum(decode(undone,'Y',1,0))+ sum(decode(done,'Y',1,0)))+笔误
      

  4.   

    sum(decode..) 基本的分组判断求和
      

  5.   

    分组是加上 ROLLUP是不是更好,既能统计子区域,又能统计区域的