Salary in effect at review time, by rating
The task
The people team asks whether higher ratings go with higher pay. For each 2024 review (reviews.review_year = 2024), pay should be the salary the employee had at the end of that review year, 2024-12-31.
salary_changes lists every salary an employee has had, each from its effective_on day. The salary in effect on a day is the one with the latest effective_on that is on or before that day.
Return one row per rating that appears in the 2024 reviews:
ratingreviews: number of 2024 reviews with that ratingavg_salary: average of the salaries in effect on2024-12-31, rounded to 2 decimal places
Sort by rating. Every employee with a 2024 review has at least one salary row on or before that day.
Expected output
ratingreviewsavg_salary- Sorted by rating ascending.
- Numbers rounded to 2 decimal places.
- 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
- Open accounts at each month end, by account typehard
- Daily spend against sign-ups for one campaignhard
- Headcount by department, empty and unassigned includedeasy
- Invoiced amount by the plan active on the issue datemedium
- Organic sign-ups during each campaign's runmedium
- Plays in the first two weeks for April joinerseasy
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL