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.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details