I have tables like the following:
recorddate score
2021-05-01 0
2021-05-01 1
2021-05-01 2
2021-05-02 3
2021-05-02 4
2021-05-03 5
2021-05-07 6
And want to get the 60th percentile for score
per week. I tried:
select distinct
recorddate
, PERCENTILE_disc(0.60) WITHIN GROUP (ORDER BY score)
OVER (PARTITION BY recorddate) AS top60
from tbl;
It returned something like this:
recorddate top60
2021-05-01 1
2021-05-02 4
2021-05-03 5
2021-05-07 6
But my desired result is like weekly aggregation (7 days). For example for the week ending on 2021-05-07:
recorddate top60
2021-05-01 ~ 2021-05-07 2
Is there a solution for this?