Second highest salary
EasyP1Coding
Table employee:
| Column | Type |
|---|---|
| id | int (primary key) |
| salary | int |
Write a query that returns the second highest distinct salary as a single column named second_highest_salary. If there is no second highest salary, return one row with NULL.
Schema
CREATE TABLE employee ( id int PRIMARY KEY, salary int NOT NULL );
Example 1
- Input
- employee: (1, 100), (2, 200), (3, 300)
- Output
- second_highest_salary: 200
Example 2
- Input
- employee: (1, 100)
- Output
- second_highest_salary: NULL
Constraints
- PostgreSQL dialect.
- Salaries can repeat; duplicates count once.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 2 visible tests, Submit all 5. ⌘Enter runs, ⌘⇧Enter submits.