Skip to main content

176. Second Highest Salary

MySQL

SELECT (
SELECT DISTINCT
salary
FROM Employee
LIMIT 1, 1
) AS SecondHighestSalary

Pandas

import pandas as pd


def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
df = employee['salary'].drop_duplicates()

second_high = df.nlargest(2).iloc[-1] if len(df) >= 2 else None

return pd.DataFrame({'SecondHighestSalary': [second_high]})