I want it to display running percentage of each sum of profit grouped by state where sum of profit per state > 0. So no deficit states should be there.
The data I am working on looks like this:
I tried various different code to achieve that, none of them worked for me. Some of them were close to what I needed some of them were not even close. My most recent one looks like this:
select state, sum_of_profit, sum_of_profit/sum(sum_of_profit) as perc
from (select state, sum(profit) as sum_of_profit
from superstore
group by state
having sum(profit) >= 0
) as temp
group by state, sum_of_profit
order by sum_of_profit desc
2条答案
按热度按时间8i9zcol21#
To display running percentage of each sum of profit, then we have to group by
sum_of_profit
only7fyelxc52#
Base Data: