oracle多字段rollup

select k.station_name_zh as fstation,
       l.station_name_zh  as pstation,
       v.countryname as countryname,
       c.bur_short_name as ssubname,
       o.bur_short_name as psubname,
       v.zoflag as zoflag,
       v.transporttype as transporttype,
      (grouping(k.station_name_zh) + grouping(l.station_name_zh) + grouping( v.countryname)+ grouping( c.bur_short_name)+ grouping(o.bur_short_name)+ grouping(v.zoflag)+ grouping(v.transporttype)) FLAG,
       decode((grouping(k.station_name_zh) + grouping(l.station_name_zh) + grouping( v.countryname)+ grouping( c.bur_short_name)+ grouping(o.bur_short_name)+ grouping(v.zoflag)+ grouping(v.transporttype)),
      0,'明细', 1,'小计1',2,'小计2', 3,'小计3',4,'小计4',5,'小计5',6,'小计6','总计') 汇总标记,
       sum(v.colnum) as colnum,
       sum(v.carnum) as carnum,
       sum(v.boxnum) as boxnum,
       sum(v.stationprofit) as stationprofit,
       sum(v.portprofit) as portprofit,
       sum(v.duolianprofit) as duolianprofit,
       sum(v.stationincome) as stationprofit,
       sum(v.portincome) as portprofit,
       sum(v.duolianincome) as duolianprofit
  from estimate_split_temp v
  left join dic_station k on v.fzid = k.id
  left join dic_station l on v.dzid = l.id
  left join dic_bureau  o on o.id = v.fbid
  left join dic_bureau  c on c.id = v.pbid
 group by rollup(k.station_name_zh, l.station_name_zh, v.countryname,c.bur_short_name,o.bur_short_name,v.zoflag,v.transporttype)

这不做多于描述,详细讲解地址

你可能感兴趣的:(数据库)