Expert Answer
Anonymous
SELECT
date,
metric_value,
ROUND(AVG(metric_value) OVER (
ORDER BY date
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
), 2) AS rolling_avg_7d
FROM
tbl
ORDER BY
date;
Palantir Technologies
Apple
EPAM Systems
Addepar
NetSuite
Riot Games
Contribute your knowledge to access all answers
#Give&Take - Share to unlock
Interview question asked to Data Scientists interviewing at Palantir Technologies, Apple, Benchling and others: Write a query to calculate the rolling average of a certain metric over a period of time?.