Salary in effect on a date for each employee
The task
Finance is rebuilding the mid-year headcount cost report. salary_changes has one row for every salary an employee has had, and a row applies from its effective_on day until the next row for that employee.
What salary was each employee on on 2024-07-01? Use the row with the latest effective_on that is on or before 2024-07-01. Employees whose first salary row is after that day had not started yet, so leave them out. Keep people who have since left.
Return employee_id and salary. Sort by employee_id.
Expected output
employee_idsalary- Sorted by employee_id ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables People team · click a name to insert it
departments7 rows in the sample
One row per department. Key: department_id.
| int | Unique id. | |
| text | Name. | |
| text | Main office city. |
employees120 rows in the sample
Everyone who has worked here, including people who left. Key: employee_id.
| int | Unique id. | |
| text | Name. | |
| int | Department. NULL for a few people between teams. | |
| int | Their manager (an employee_id). NULL for the CEO. | |
| text | Title. | |
| date | First day. | |
| date | Last day. NULL while employed. | |
| numeric(10,2) | Current (or final) yearly salary, USD. |
salary_changes367 rows in the sample
Every salary someone has had, from the day it applied. Key: employee_id, effective_on.
| int | The employee. | |
| date | First day of this salary. | |
| numeric(10,2) | Yearly salary, USD. |
reviews301 rows in the sample
Year-end review ratings. Key: employee_id, review_year.
| int | The employee. | |
| int | Year reviewed. | |
| int | 1 (low) to 5 (high). |
Related questions
- Current order copy when two copies share a timestamphard
- Find exact duplicate rows in a raw order loadeasy
- Keep the first purchase event for each web usermedium
- Orders by current status from a raw loadmedium
- Customers with several accounts under one emaileasy
- Emails shared by accounts that disagree on countrymedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL