Employee seniority

conditional logic

Employee seniority

Google SQL Interview Question

Google's HR team is setting up a mentoring program and wants to label each employee by how long they have been with the company.

Show every employee's name, hire_date and a label as seniority. The label is "Senior" for anyone hired before 2020, "Mid-level" for anyone hired in 2020 or 2021, and "Junior" for anyone hired in 2022 or later.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Analytics Engineer

employeesTable16 rows

Column NameType
employee_idBIGINT
nameVARCHAR
departmentVARCHAR
salaryBIGINT
manager_idBIGINT
hire_dateDATE

employeesExample Input

employee_idnamedepartmentsalarymanager_idhire_date
2Mei LinEngineering18500012018-06-04
4James ParkEngineering12800022019-09-02
8Hannah WeberAnalytics13400072020-01-13
10Kenji SatoAnalytics10900082022-03-07
13Lucia FerrariSales104000112021-02-15
14Peter NovakSales96000122022-09-12

Example Output

namehire_dateseniority
Hannah Weber2020-01-13Mid-level
James Park2019-09-02Senior
Kenji Sato2022-03-07Junior
Lucia Ferrari2021-02-15Mid-level
Mei Lin2018-06-04Senior
Peter Novak2022-09-12Junior

Explanation

Mei Lin was hired in 2018 and James Park in 2019, so both are Senior. Hannah Weber and Lucia Ferrari were hired in 2020 and 2021, so they are Mid-level. Kenji Sato and Peter Novak joined in 2022, so they are Junior.

The example above is a small slice of the data. Your query runs against the full tables.