Skip to the content

How many payrolls does it cover?

Problem

Management hands out the budget and has never set it next to what each department pays in salaries. For each department where someone works, show its name, its budget, its payroll (the sum of its people's monthly salaries), and how many times that payroll goes into its budget, rounded to 1 decimal, in that order.

An empty department has no payroll to compare with, and someone who doesn't belong to any department isn't on anyone's payroll.

What it has to return

These rows, in any order

namebudgetpayrolltimes
Sales5000078006.4
Tech80000127006.3
Design30000240012.5

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT d.name, e.salary
FROM employees e
JOIN departments d
  ON e.dept_id = d.id
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →