Retrieve Employee Salary and Department Maximum

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

sql

SELECT name, salary, MAX(salary) OVER (PARTITION BY department_id) AS max_department_salary FROM employees;

This query uses a window function to return each employee's name and salary alongside the highest salary found within their respective department.

PromptDB can make mistakes. Please double-check responses.