Segundo Salario más Alto
Tabla: Employee
Escribe una solución para encontrar el segundo salario distinto más alto de la tabla Employee. Si no hay un segundo salario más alto, devuelve null (Devuelve None en Pandas).
Ejemplos
Ejemplo 1
Input:
Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+Output:
+---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+Ejemplo 2:
Input:
Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+Output:
+---------------------+ | SecondHighestSalary | +---------------------+ | null | +---------------------+Soluciones
Python
import pandas as pd
def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
unique_salaries = employee['salary'].drop_duplicates().sort_values(ascending=False)
if len(unique_salaries) >= 2:
second_highest = unique_salaries.iloc[1]
else:
second_highest = None
return pd.DataFrame({'SecondHighestSalary': [second_highest]})