RL SumAmount RL SumAmount
Alex 120 Alex 24.00%
Jonny 122 Jonny 24.40%
Jack 13 Jack 2.60%
David 125 David 25.00%
Mike 120 Mike 24.00%
总计500总计100.00%
我试图使用sql计算列总计百分比,如下面的屏幕截图但是遇到问题
答案 0 :(得分:0)
获得比率:
select t.*, sumamount/tot.total
from table t cross join
(select sum(sumamount) as total from table t) tot;
如果您希望将其表示为百分比:
select t.*, concat(format(sumamount/tot.total, 2), '%')
from table t cross join
(select sum(sumamount) as total from table t) tot;