table 如下
现在想得出分类金额占比的结果,如下图:
即order by date,category
最后那列amt_percent是图一中每一天的每一类的金额在整个表所有金额总和的占比,求问如何实现最后那列amt_percent?楼主想到的方法算出来不对:
select
date,
category,
catamt,
catamt/sum(catamt) amt_percent
from
(select
date,
category,
case when category = 'A' then sum(amount)
 when category = 'B' then sum(amount)
 when category = 'C' then sum(amount)
end catamt
from Tb
) a
group by date, category