Rolling Average Steps
Start Timer
0:00:00
As a data analyst in a fitness app company, you are tasked with analyzing the user’s daily step count.
Write a SQL query to calculate the 3-day rolling average of steps for each user, rounded to the nearest whole number.
Notes: The rolling average should only be calculated for days where there are 3 previous days of step counts, including the current day. The first 2 days for any user should be excluded.
Example:
Input:
daily_steps
table
Column | Type |
---|---|
id | INTEGER |
user_id | INTEGER |
steps | INTEGER |
date | DATE |
Output:
Column | Type |
---|---|
user_id | INTEGER |
date | DATE |
avg_steps | FLOAT |
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments