select nvl(supdep,'合計') hj,sum(xj),sum(fundtype1),sum(fundtype2),sum(fundtype3) from (
select supdep ,nvl(fundtype1,0)+nvl(fundtype2,0)+nvl(fundtype3,0) xj,fundtype1,fundtype2,fundtype3 from (
select '['||a.itemcode||']'||a.itemname supdep,c.fundtype,sum(t.amount) amount from ba_bgt_budget t
left join fp_t_ctfundtype c on t.fund_type_id=c.itemid and ep_fun_validDate(c.startdate,c.enddate,t.dbyear)=1
left join fp_t_ctagency a on t.bgt_dept_id=a.itemid and ep_fun_validDate(a.startdate,a.enddate,t.dbyear)=1
where t.billstatus=2 group by '['||a.itemcode||']'||a.itemname,c.fundtype
) pivot(sum(amount) for fundtype in (1 fundtype1,2 fundtype2,3 fundtype3)) order by supdep
) group by rollup(supdep)
order by grouping(supdep) desc


我想把合計行放到第一行,第一張是未分組排序(order by grouping(supdep) desc)顯示沒問題,第二張排完序列之后,101、131為啥在最下邊?
正常求合計行,正序倒序都沒問題的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/113470.html
標籤:開發
下一篇:Oracle分享
