Leetcode Problem 2854. Rolling Average Steps

2854. Rolling Average Steps

Leetcode Solutions

Calculating-Day Rolling Averages Using Window Functions

  1. Use the AVG() function with the OVER() clause to calculate the rolling average of steps over a window defined by the current row and the two preceding rows.\n2. Use the LAG() function to get the date two rows before the current row within the same window.\n3. Use a subquery or common table expression (CTE) to perform the above calculations for each user and date.\n4. In the outer query, filter the results to only include rows where the date difference between the current row and the date obtained from the LAG() function is exactly two days.\n5. Order the final result by user_id and steps_date in ascending order.
\nerDiagram\n  Steps {\n    int user_id\n    int steps_count\n    date steps_date\n    user_id *--* steps_date : is the primary key\n  }\n

Calculating-Day Rolling Averages Using Self-Join

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...