Calculate Employee Salary Percentage by Department

Find the percentage contribution of each employee's salary to the total department salary.

sql

SELECT name, salary, (salary / SUM(salary) OVER (PARTITION BY department_id)) * 100 AS percentage_contribution FROM employees;

This query calculates the percentage of each employee's salary relative to the total salary of their respective department using the SUM() window function partitioned by department_id.

PromptDB can make mistakes. Please double-check responses.