I want aggregate my walks with animals by weeks groupping my rows in 1 group if break between weeks was greater than 2 weeks.
I have my table:
Create table test.walk (animal text, week integer)
with row for each walk i want to group:
insert into test.walk values ('DOG', 2)
insert into test.walk values ('DOG', 3)
insert into test.walk values ('DOG', 4)
insert into test.walk values ('CAT', 1)
insert into test.walk values ('CAT', 1)
insert into test.walk values ('CAT', 11)
insert into test.walk values ('CAT', 12)
insert into test.walk values ('CAT', 13)
I struggle with dense_rank() and lag() window functions, but have no luck to get additional column where I should get 3 distinct values as a result.
Here is my desired output:
What combination of window functions should I use to get two WALK_NO for CAT? (becase after week 1 cat waited for me longer that 2 weeks)