SQL

Write a query to calculate the rolling average of a certain metric over a period of time?

Data Scientist

Palantir Technologies

Apple

EPAM Systems

Addepar

NetSuite

Riot Games

Did you come across this question in an interview?

Answers

Expert Answer

Anonymous

4.2Exceptional
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;

  • Write a query to calculate the rolling average of a certain metric over a period of time?
  • What is your process for determining the rolling average of a specific metric over a certain length of time?
  • How do you compute the rolling average of a metric across a set period of time?
  • Would you walk me through your approach for calculating the rolling average of a metric over a time span?
  • Can you demonstrate how you would determine the rolling average for a certain metric over a designated period of time?
  • What steps do you take to calculate the rolling average of a particular metric over a given time frame?
  • How do you derive the rolling average for a specific metric across a predetermined period of time?
  • Could you describe how you calculate the rolling average for a metric over a particular time length?
  • What is the process you use to determine the rolling average of a metric over a set time period?
  • Would you describe your methodology for calculating the rolling average of a metric over a specific interval?
  • Can you explain how you would go about calculating the rolling average for a particular metric over a given time period?
Try Our AI Interviewer

Prepare for success with realistic, role-specific interview simulations.

Try AI Interview Now

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?.