Created
June 20, 2017 05:35
-
-
Save whbzju/a3cffa7f210f32050227c1f578979459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cumsum | |
select | |
a.id, | |
a.sum_all, | |
sum(a.sum_all) over (order by a.sum_all, a.id | |
rows between unbounded preceding | |
and current row) | |
as csum | |
from | |
( select col1 as id, | |
sum(col2) as sum_all | |
from t | |
group by col1 | |
) a | |
order by | |
sum_all, id ; | |
select | |
col1 as id, | |
sum(col2) as sum_all, | |
sum(sum(col2)) over (order by sum(col2), col1 | |
rows between unbounded preceding | |
and current row) | |
as csum | |
from | |
t | |
group by | |
col1 | |
order by | |
sum_all, id ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment