Median salary per company
MediumP2Coding
Table employee:
| Column | Type |
|---|---|
| id | int (primary key) |
| company | text |
| salary | int |
Return the median salary for each company. When a company has an even number of employees, the median is the average of the two middle salaries.
Output columns: company, median_salary.
Schema
CREATE TABLE employee ( id int PRIMARY KEY, company text NOT NULL, salary int NOT NULL );
Example 1
- Input
- employee: (1, A, 100), (2, A, 300), (3, A, 200)
- Output
- A: 200
Example 2
- Input
- employee: (1, B, 100), (2, B, 200), (3, B, 300), (4, B, 500)
- Output
- B: 250
Constraints
- PostgreSQL dialect.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 3 visible tests, Submit all 6. ⌘Enter runs, ⌘⇧Enter submits.