Colleagues hired in the same month and department
The task
The people team wants to pair up colleagues who started together, for an onboarding buddy programme.
List every pair of different employees who are in the same department and whose hire_date falls in the same calendar month of the same year. Include people who have since left. People with no department (department_id is NULL) are not paired with anyone. A buddy cannot be someone's own manager, so leave out a pair when one of the two is the other's direct manager (manager_id). Each pair appears once, with the lower employee_id first.
Return employee_a_id, employee_b_id, department_name and hire_month (the first day of the month they were hired). Sort by hire_month, then employee_a_id, then employee_b_id.
Expected output
employee_a_idemployee_b_iddepartment_namehire_month- Sorted by hire_month ascending, then employee_a_id ascending, then employee_b_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
- Skip-level managers and how many people they covereasy
- Employees paid more than their managermedium
- Products bought together in the same ordermedium
- Raises of 9.5 percent or more over the previous salaryhard
- Repeat tickets from the same customer within a weekeasy
- Trips between a rider and a driver they already knowmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL