Each row of staff_wages holds one employee's id and wage. Find the second highest distinct wage in the table and return it as second_highest_wage. If there is no second highest distinct wage, return NULL.
Input Table(s)
staff_wages
| Column | Type | Meaning |
|---|
| staff_id | INT | Employee identifier |
| wage | INT | The employee's wage |
Primary key: staff_id (unique values).
Output Contract
| Column | Type | Meaning |
|---|
| second_highest_wage | INT | The second highest distinct wage, or NULL if there is none |
Always return exactly one row with this one column. With a single row there is no ordering to specify. No rounding applies.
Example
staff_wages
Expected result:
The wages are 500, 700 and 900, so the highest is 900 and the second highest distinct wage is 700.
If every employee earned 900, there would be only one distinct wage, and the expected result would be a single row with second_highest_wage equal to NULL.
Constraints and Clarifications
-
Wages are compared as distinct values. With wages 900, 900 and 700 the answer is 700, because the two 900s count as one value.
-
If the table is empty or has only one distinct wage, return one row containing NULL. An empty result set is wrong.
-
Ignore rows whose
wage
is NULL; they do not count as a wage.
-
Several employees may share the second highest wage. The answer is still the single wage value.