Departments 9–13: 2nd latest hire
Level: MiddleTopic: Subqueries100 XP
Instructions
For each department with department_id from 9 to 13 inclusive, find the employees (including those who were fired) whose hire date (hired_at) is the second latest (second most recent) among the distinct hired_at values of all employees of that department. If several employees in the department qualify (hired on the same day), output all of them. Columns: id, name, department_id, hired_at. Row order does not matter.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Exactly oneZero or oneZero or more
Table relationships
- N:1Many-to-one
employees.→department_id departments.id - N:1Many-to-one
employees.→manager_id employees.id - N:1Many-to-one
departments.→parent_id departments.id - N:1Many-to-one
salary_history.→employee_id employees.id
Table data
PostgreSQL
Select a table in the diagram or list to view its rows.