select 
  名称,
  sum(decode(ceil(to_char(统计时间,'dd')/10),1,总数,0)) 上旬,
  sum(decode(ceil(to_char(统计时间,'dd')/10),2,总数,0)) 中旬,
  sum(decode(ceil(to_char(统计时间,'dd')/10),3,总数,0)) 下旬,
  sum(总数) 总数
from tab
group by 名称;

解决方案 »

  1.   

    select 
      名称,
      sum(case ceil(to_char(统计时间,'dd')/10) when 1 then 总数 else 0) 上旬,
      sum(case ceil(to_char(统计时间,'dd')/10) when 2 then 总数 else 0) 中旬,
      sum(case ceil(to_char(统计时间,'dd')/10) when 3 then 总数 else 0) 下旬,
      sum(总数) 总数
    from tablename 
    group by 名称
      

  2.   

    select 
      名称,
      sum(case ceil(to_char(统计时间,'dd')/10) when 1 then 总数 else 0 end) 上旬,
      sum(case ceil(to_char(统计时间,'dd')/10) when 2 then 总数 else 0 end) 中旬,
      sum(case ceil(to_char(统计时间,'dd')/10) when 3 then 总数 else 0 end) 下旬,
      sum(总数) 总数
    from tablename 
    group by 名称
      

  3.   

    select 
      decode(grouping(名称),1,'所以名称求总',名称) 名称,
      case floor(to_char(统计时间,'dd')/10) when 0 then 上旬,
                                            when 1 then 中旬,
                                            when 2 Then 下旬
      End,
      sum(总数) 总数
    from tablename 
    group by rollup(名称,
    case floor(to_char(统计时间,'dd')/10) when 0 then 上旬,
                                          when 1 then 中旬,
                                          when 2 Then 下旬
    End)
      

  4.   

    呵呵,刚才忙,没注意,31号没有拎出来处理
    select 
      名称,
      sum(decode(ceil(to_char(统计时间,'dd')/10),1,总数,0)) 上旬,
      sum(decode(ceil(to_char(统计时间,'dd')/10),2,总数,0)) 中旬,
      sum(decode(ceil(to_char(统计时间,'dd')/10),3,总数,4,总数,0)) 下旬,
      sum(总数) 总数
    from tab
    group by 名称;或者select 
      名称,
      sum(decode(ceil(to_char(统计时间,'dd')/10),1,总数,0)) 上旬,
      sum(decode(ceil(to_char(统计时间,'dd')/10),2,总数,0)) 中旬,
      sum(decode(sign(ceil(to_char(统计时间,'dd')/10)-2),1,总数,0)) 下旬,
      sum(总数) 总数
    from tab
    group by 名称;