Starting at the bottom
- O(n²) · Very hard
- Full plan
- SQL
- changing data
- subqueries
Problem
Management approved a raise of 150 a month and wants to start at the bottom: it goes to whoever earns the least in each department. If two people share their department's lowest salary, both get it. In a department of one, that one person is the lowest paid.
Carol has no department, and her salary stays as it is.
Write the change. It's graded by looking at every salary in the company afterward, so it can't give anyone a raise they weren't due.
What it has to return
After your code, this query runs
SELECT id, name, salary FROM employees;These rows, in any order
| id | name | salary |
|---|---|---|
| 1 | Carol | 5200 |
| 2 | Mark | 3800 |
| 3 | Paige | 4100 |
| 4 | Rachel | 2050 |
| 5 | Nicole | 2100 |
| 6 | Samuel | 3000 |
| 7 | Lydia | 3000 |
| 8 | Frank | 2750 |
| 9 | Grace | 2550 |
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
UPDATE employees
SET salary = salary + 150
WHERE salary = (
SELECT MIN(salary)
FROM employees
);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
- The library forgetsSQL · changing data · subqueries
- The next rung upSQL · window functions · subqueries
- The register, day by daySQL · window functions · grouping · conditionals
- The third stampSQL · window functions · joins · dates
- The week of the 4thSQL · dates · grouping · strings
- What went out todaySQL · changing data · subqueries · nulls