云醉月未眠

导航

数据库中 显示 小计 与 总计

select rownum seq,
       decode(rn, 1, gid) gid,
       decode(rn, 1, gname) gname,
       gcolour,
       gwithin,
       gsize,
       gnumber
  from (select t.*, row_number() over(partition by gid order by gnumber) rn
          from (select GId,
                       gname,
                       gcolour,
                       gwithin,
                       gsize,
                       sum(gnumber) gnumber
                  from t_goods
                 group by GId, gname, gcolour, gwithin, gsize
                union all
                select gid, gname, nullnull'小计'sum(gnumber)
                  from t_goods
                 group by gid, gname
                union all
                select nullnullnullnull'总计'sum(gnumber)
                  from t_goods) t);
 
  
       SEQ GID        GNAME                GCOLOUR       GWITHIN GSIZE         GNUMBER
---------- ---------- -------------------- ---------- ---------- ---------- --------
         1 A01        上衣                 红                  0 S                  10
         2                                 白                  0 M                  20
         3                                 黑                  0 L                  30
         4                                                       小计               60
         5 A02        下衣                 红                  0 S                   5
         6                                 白                  0 M                  15
         7                                                       小计               20
         8 A03        下衣                 红                  0 S                   5
         9                                 白                  0 M                  15
        10                                                       小计               20
        11                                                       总计              100
 
 
 
 
 
 
 
 
 
 
 
select t.*,row_number()OVER(PARTITION by ylmc order by gh ) rn
  from  (select gh ,ylmc ,sum(syjc) ,sum(slyc) ,sum(smt) ,sum(syg) ,sum(gcls) ,sum(fmt) ,sum(fyp) ,sum(fyg) ,sum(gclf) ,sum(sysh) ,sum(fysh) ,sum(ccsh) ,sum(bygc) ,sum(byzc)
                   from zy_ylhz_two abc group by gh,ylmc
                union ALL    
                    select '小计',ylmc,sum(syjc),sum(slyc),sum(smt),sum(syg),sum(gcls),sum(fmt),sum(fyp),sum(fyg),sum(gclf),sum(sysh),sum(fysh),sum(ccsh),sum(bygc),sum(byzc)
                    from zy_ylhz_two group by ylmc
                union ALL
                    select '总计','',sum(syjc),sum(slyc),sum(smt),sum(syg),sum(gcls),sum(fmt),sum(fyp),sum(fyg),sum(gclf),sum(sysh),sum(fysh),sum(ccsh),sum(bygc),sum(byzc)
                    from zy_ylhz_two )t

 

 
 
 
 
 
 
 
 
 
 
 

posted on 2017-11-27 11:59  别皱眉  阅读(821)  评论(0编辑  收藏  举报