Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Moving Average Calculation
00:00
5 left

Moving Average Calculation

MediumSQL · PostgreSQL

Problem

Calculate a moving average for TaskRabbit metrics using SQL.

Use the taskrabbit_metrics table and calculate a three-observation moving average for completed_tasks. Ignore rows where the metric value is NULL.

Output

  1. One row per completed_tasks observation.
  2. Columns: metric_date, metric_name, and moving_average.
  3. Round moving_average to two decimal places and order by metric_date ascending.

Schema

taskrabbit_metrics
ColumnTypeDescription
metric_idPKINTUnique metric observation identifier
metric_nameVARCHAR(100)Name of the TaskRabbit metric
metric_dateDATEDate of the metric observation
metric_valueDECIMAL(12,2)Observed metric value
Tablestaskrabbit_metrics
Interviewer

Your question is Moving Average Calculation. Start with the requirements and the one table in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.