Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Youngest Age in SQL

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Second Youngest Age in SQL. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

LatentView Analytics wants to validate age-based workforce reporting for its active analysts. Write a PostgreSQL query to find the second-youngest distinct age among employees whose current workforce status is Active.

Requirements

  1. Join employees with employee_statuses using employee_id.
  2. Exclude employees without an active status and ignore NULL ages.
  3. Rank distinct ages from youngest to oldest and return the age with rank 2.
  4. Return one column named second_youngest_age.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee name
ageINTEmployee age
employee_statuses
ColumnTypeDescription
status_idPKINTUnique status record identifier
employee_idINTReferences employees.employee_id
current_statusVARCHAR(20)Current workforce status
Tablesemployeesemployee_statuses
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results