FastPrepSecond-Highest Distinct Salary

Second-Highest Distinct Salary

Chubb logoChubb● EasyNEW GRADPHONE SCREEN

Problem statement

The employees table contains one row per employee with an optional salary.

Return exactly one row and one column named second_highest_salary. Its value is the second-highest distinct non-NULL salary. If fewer than two distinct non-NULL salaries exist, return NULL.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

employees

One row per employee.

ColumnTypeNullableDescription
employee_idPKIntegerNo—
salaryIntegerYes—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
second_highest_salaryIntegerYes—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • employee_id is a unique integer.
  • salary is an integer or NULL.
  • Duplicate salary values share the same rank.
  • The result always contains exactly one row.

More Chubb problems

See Chubb hiring insights