Mid
Window Functions
SQL & Databases
Write a query to show department salary share using SUM OVER.
Short answer: Compute each employee’s salary share within department via Salary / SUM(Salary) OVER (PARTITION BY DepartmentId).
Sample solution
T-SQL
SELECT EmpId, DepartmentId, Salary,
CAST(100.0 * Salary / SUM(Salary) OVER (PARTITION BY DepartmentId) AS DECIMAL(5,2)) AS DeptPct
FROM Employees;
Window aggregates keep detail rows — unlike GROUP BY alone.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png