Calculate Employee and Department Average Salary

Find each employee's salary along with the department's average salary.

sql

SELECT name, salary, AVG(salary) OVER (PARTITION BY department_id) AS department_avg_salary FROM employees;

This query uses a window function to calculate the average salary for each department and displays it alongside the individual salary for every employee in the "employees" table.

PromptDB can make mistakes. Please double-check responses.