FastPrepSecond Highest Salary

Second Highest Salary

Hartford Financial Services logoHartford Financial Services● EasyFULLTIMEONSITE INTERVIEW

Problem statement

The table employees contains salary values. Find the second-highest distinct, non-NULL salary.

Equal salaries share one rank. Ignore rows whose salary is NULL.

Return exactly one row and one column named second_highest_salary. If fewer than two distinct non-NULL salaries exist, that row must contain 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

Only the salary column is needed for this query.

ColumnTypeNullableDescription
salaryIntegerYesEmployee salary; NULL denotes an unknown salary.

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
second_highest_salaryIntegerYesSecond-highest distinct known salary, or NULL when absent.

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

Constraints

  • employees contains between 0 and 2000 rows.
  • Each known salary is an integer from 0 through 10^9, inclusive.
  • The table may contain duplicate salary values and NULL salaries.

More Hartford Financial Services problems

See Hartford Financial Services hiring insights