Skip to content
RED SAGSkills

Salary Share of Department

For each employee, compute their salary as a percentage of their department's total payroll: 100.0 * salary / dept_total, rounded with ROUND(x, 2). Every employee belongs to a department and has a salary. Names are unique.

Return columns dept, name, salary, pct_of_dept. Order by dept ascending, pct_of_dept descending, then name ascending.

Schema

CREATE TABLE employees (
  emp_id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL,
  salary INTEGER NOT NULL
);

Sample data

employees

emp_idnamedeptsalary
1AriaDesign9000
2BilalDesign6000
3CleoEngineering15000
4DevEngineering12000
5EunEngineering13000
6FayeSupport5000
Hint 1

SUM(salary) OVER (PARTITION BY dept) puts the department total on every row without collapsing rows.

Discussion 0

Join free to post in the discussion.

Good practice for: Data Analyst, Business Analyst, Data Scientist

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.