You are given a Salary table that contains employee information and their yearly salaries. However, some records are outdated and contain old salary information.
Write a solution to find the current salary of each employee, assuming that salaries increase each year (higher salary = more recent).
Return the result table with emp_id, firstname, lastname, salary, and department_id, ordered by emp_id in ascending order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
emp_id
PK
|
int | Employee ID |
firstname
|
varchar | Employee first name |
lastname
|
varchar | Employee last name |
salary
PK
|
varchar | Employee yearly salary |
department_id
|
varchar | Department identifier |
Input & Output
| emp_id | firstname | lastname | salary | department_id |
|---|---|---|---|---|
| 1 | John | Doe | 50000 | IT |
| 1 | John | Doe | 75000 | IT |
| 2 | Jane | Smith | 60000 | HR |
| 2 | Jane | Smith | 80000 | HR |
| 3 | Bob | Wilson | 45000 | Finance |
| emp_id | firstname | lastname | salary | department_id |
|---|---|---|---|---|
| 1 | John | Doe | 75000 | IT |
| 2 | Jane | Smith | 80000 | HR |
| 3 | Bob | Wilson | 45000 | Finance |
John has two salary records (50000, 75000), so we select the higher one (75000). Jane has two records (60000, 80000), so we select 80000. Bob has only one record, so we keep 45000.
| emp_id | firstname | lastname | salary | department_id |
|---|---|---|---|---|
| 1 | Alice | Johnson | 95000 | Engineering |
| 2 | Charlie | Brown | 72000 | Marketing |
| emp_id | firstname | lastname | salary | department_id |
|---|---|---|---|---|
| 1 | Alice | Johnson | 95000 | Engineering |
| 2 | Charlie | Brown | 72000 | Marketing |
When each employee has only one salary record, all records are returned as they represent the latest (and only) salary for each employee.
Constraints
-
1 ≤ emp_id ≤ 1000 -
salaryis stored as varchar but represents numeric values -
firstnameandlastnameare non-empty strings -
department_idis a valid department identifier