Lets say I have following data
id some_date days weeks
1111111111111111111111111 2021-03-01 2 1
1111111111111111111111111 2021-03-01 8 2
1111111111111111111111111 2021-03-01 9 2
1111111111111111111111111 2021-03-01 22 4
1111111111111111111111111 2021-03-01 24 4
and I want to calculate lifetime week totals for every row. For instance, the result for data above would be as following:
id some_date days weeks lifetime_weeks
1111111111111111111111111 2021-03-01 2 1 1
1111111111111111111111111 2021-03-01 8 2 2
1111111111111111111111111 2021-03-01 9 2 2
1111111111111111111111111 2021-03-01 22 4 3
1111111111111111111111111 2021-03-01 24 4 3
I tried to implement it with window functions, but as it is not allowed to have distinct inside window functions I ended up with errors
COUNT(distinct id) OVER(PARTITION BY id order by days rows unbounded preceding) as lifetime_weeks
How can I do the same thing without window function? Any help would be much appreciated