Second Highest Salary
Updated
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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| salary | Integer | Yes | Employee salary; NULL denotes an unknown salary. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| second_highest_salary | Integer | Yes | Second-highest distinct known salary, or NULL when absent. |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
employeescontains between0and2000rows.- Each known salary is an integer from
0through10^9, inclusive. - The table may contain duplicate salary values and
NULLsalaries.
More Hartford Financial Services interview questions
Similar questions at other companies
- Latest New JobSphere · ONSITE INTERVIEW
- In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Weekend Appointments for Consular Services ReschedulingMcKinsey & Company · OAMcKinsey & Company interview questions
- Benchmarking Tool ReportPalantir · OAPalantir interview questions
- Prepare Taxi Driver Classification DataBoston Consulting Group · OABoston Consulting Group interview questions
- Clean the TapeMillennium · OAMillennium interview questions
- Summarize Customer RecordsAgoda · OAAgoda interview questions
- Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
- Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW