What does the following window expression do? AVG(salary) OVER (PARTITION BY dept ORDER BY hire_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)

SQL Data Analyst Medium

SQL Data Analyst — Medium

What does the following window expression do? AVG(salary) OVER (PARTITION BY dept ORDER BY hire_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)

Key points

  • This expression uses the AVG function to find the average salary.
  • The PARTITION BY dept divides the data by department.
  • The ORDER BY hire_date arranges the data in chronological order.
  • The ROWS BETWEEN 2 PRECEDING AND CURRENT ROW specifies the window frame for the moving average.

Ready to go further?

Related questions