Slackbot
01/11/2024, 5:42 AMAbhishek Agarwal
01/11/2024, 8:42 AMMike Sherman
01/11/2024, 2:26 PMJohn Kowtko
01/11/2024, 2:56 PMwith tmp as (
select channel, flags, count(*) cnt
from wikipedia
group by 1, 2
)
select channel, flags, cnt,
sum(cnt) over (order by channel rows between 1 following and 2 following) "range 1f2f",
sum(cnt) over (order by channel rows between 1 preceding and 2 following) "range 1p2f"
from tmp
@Mike Sherman, the only way I found this stuff is to create a simple test case with relatively low numbers that are unique enough that you can figure out by inspection what's going on.
A few months back I hit an offset error with the lower bound in the framing clause, but I'm pretty sure that one was already fixed. This one is new to me.John Kowtko
01/11/2024, 3:01 PMwith tmp as (
select channel, flags, count(*) cnt
from wikipedia
group by 1, 2
)
select channel, flags, cnt,
sum(cnt) over (order by channel rows between 3 following and 2 following) "range 1f2f",
sum(cnt) over (order by channel rows between 3 preceding and 2 following) "range 1p2f"
from tmpMike Sherman
01/11/2024, 3:27 PMMike Sherman
01/11/2024, 4:00 PMflags in mine. I can load new data, that should add flags if it's not there. Not urgent, just wanted to follow up since I'm getting a better handle on window functions and use cases like this are great for learning! https://media.giphy.com/media/8dYmJ6Buo3lYY/giphy.gif▾
John Kowtko
01/11/2024, 4:06 PMAbhishek Agarwal
01/11/2024, 4:14 PMMike Sherman
01/11/2024, 4:19 PMMike Sherman
01/11/2024, 4:26 PMSoumyava Das
01/23/2024, 5:21 AMRahul Sharma
01/24/2024, 11:04 AM