SQL Practice Logo

SQLPractice Online

Scenario SQL Question

3-Row Moving Average of Salaries (Explicit ROWS Frame)

Build mastery in Ctes Window with this scenario-based SQL challenge and live execution support.

Problem Statement

Within each department, ordered by hire_date, compute the moving average of salary over the current row and the two before it (a 3-row trailing window). Return department_name, first_name, last_name, hire_date, salary, moving_avg_3 (rounded to 2) — ordered by department_name, hire_date, employee_id.

Relevant Tables

employeesdepartments

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: