Hired in 2023
SQL data engineering interview problem. Difficulty: beginner. Pattern: Date Functions. About 8 minutes. Free to practice.
HR is writing a yearly report about hiring. Find all the employees who were hired during the year 2023, which means from 1 January 2023 up to the end of 31 December 2023. Return name and hire_date. Sort by hire_date from the earliest, and when two people were hired on the same day, sort by name from A to Z.
Requirements
- Keep only the rows where hire_date falls in the year 2023.
- Include 1 January 2023 and include 31 December 2023.
- Sort by hire_date first, then by name.
Constraints
- The table is employees.
- Return only these 2 columns, in this order: name, hire_date.
- Write the date range as 'on or after the start' and 'before the end of the range'. In SQL: hire_date >= '2023-01-01' AND hire_date < '2024-01-01'.
Examples
Input: employees name | hire_date Bob Kumar | 2023-03-01 Eve Ng | 2024-01-05 Max Reed | 2023-12-01 Output: name | hire_date Bob Kumar | 2023-03-01 Max Reed | 2023-12-01 Why this passes: Eve is 2024 and drops out. Prefer a date range over YEAR(hire_date) = 2023.
Topics: lakebench, sql, dates, where.
More SQL interview questions · All interview problems · Learn data engineering
Hired in 2023
Interview-style drill: Filter employees hired during calendar year 2023.
Find employees hired in 2023. Columns: `name`, `hire_date`. Order by `hire_date`, then `name`.