SQL: Moving Average
Medium
SQL — Window Functions
SQL
Moving Average
ROWS
Calculate 3-day moving average of stock prices.
Constraints
Write standard SQL (MySQL 8.0 compatible).
Examples
Example 1:
Input: day price
1 100
2 110
3 105
Output:
Example 2:
Input: day price
1 100
2 110
3 105
Output:
Hints
AVG with ROWS BETWEEN.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console