Calculate Median as a Window Function on Percentage Field for Limited Rows in AWS Athena

  Kiến thức lập trình

I have a table with date, company_id and capacity_percentage fields. My goal is to get the median of the preceding 3 rows on each row of the capacity_percentage field, partitioned by company_id and ordered by date.

I tried the following and it’s wrong. Please help! Thanks.

APPROX_PERCENTILE(capacity_percentage,0.5) OVER (PARTITION BY company_id ORDER BY date asc ROWS BETWEEN 3 PRECEDING AND CURRENT ROW)

LEAVE A COMMENT