Created
May 13, 2016 22:49
-
-
Save chenzhan/a3ca7588a0a245c4e2a1560387efb971 to your computer and use it in GitHub Desktop.
Window Function Example
This file contains hidden or 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
with t as ( | |
select x, y+x as y | |
from generate_series(1, 3) as t1(x) full outer join generate_series(11, 13) as t2(y) on 1=1 | |
) | |
select x, y, | |
array_agg(x) over () as frame, | |
sum(x) over () as sum, | |
sum(x) over (partition by x order by y) as sum_rolling, | |
count(1) over (partition by x) as cnt_part, | |
count(1) over (partition by x order by y) as cnt_rolling, | |
count(1) over (partition by x rows unbounded preceding) as cnt_part, | |
lag(y, 1) over (partition by x) as y_lag, | |
x::float/sum(x) over () as part | |
from t | |
; |
Author
chenzhan
commented
May 13, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment