Loading problem...
An HR analytics platform stores historical compensation snapshots for employees and needs a reliable way to retrieve each employee's current pay record.
Table: Salary
Data model assumptions:
Task: Return the latest snapshot for each employee, where latest is defined as the row with the maximum salary for that employee.
Output columns:
Supported submission environments:
Salary:
| emp_id | firstname | lastname | salary | department_id |
|--------|-----------|----------|--------|---------------|
| 1 | Todd | Wilson | 106119 | D1006 |
| 1 | Todd | Wilson | 110000 | D1006 |
| 2 | Justin | Simon | 128922 | D1005 |
| 2 | Justin | Simon | 130000 | D1005 |
| 3 | Kelly | Rosario | 42689 | D1002 |[
{"emp_id":1,"firstname":"Todd","lastname":"Wilson","salary":110000,"department_id":"D1006"},
{"emp_id":2,"firstname":"Justin","lastname":"Simon","salary":130000,"department_id":"D1005"},
{"emp_id":3,"firstname":"Kelly","lastname":"Rosario","salary":42689,"department_id":"D1002"}
]Employees 1 and 2 have multiple snapshots, so the larger salary row is selected. Employee 3 has one row, which is already current.
Salary:
| emp_id | firstname | lastname | salary | department_id |
|--------|-----------|----------|--------|---------------|
| 10 | Rhea | Carter | 50000 | D2001 |
| 10 | Rhea | Carter | 62000 | D2001 |
| 11 | Noah | Patel | 72000 | D2003 |
| 11 | Noah | Patel | 95000 | D2003 |
| 12 | Ira | Lane | 48000 | D2001 |[
{"emp_id":10,"firstname":"Rhea","lastname":"Carter","salary":62000,"department_id":"D2001"},
{"emp_id":11,"firstname":"Noah","lastname":"Patel","salary":95000,"department_id":"D2003"},
{"emp_id":12,"firstname":"Ira","lastname":"Lane","salary":48000,"department_id":"D2001"}
]The latest snapshot for each employee is exactly the row with maximum salary per emp_id.
Salary:
| emp_id | firstname | lastname | salary | department_id |
|--------|-----------|----------|--------|---------------|
| 21 | Mina | Shah | 90000 | D3010 |
| 22 | Owen | Gray | 83000 | D3010 |
| 22 | Owen | Gray | 91000 | D3010 |
| 22 | Owen | Gray | 98000 | D3010 |
| 23 | Ava | Reed | 61000 | D3022 |[
{"emp_id":21,"firstname":"Mina","lastname":"Shah","salary":90000,"department_id":"D3010"},
{"emp_id":22,"firstname":"Owen","lastname":"Gray","salary":98000,"department_id":"D3010"},
{"emp_id":23,"firstname":"Ava","lastname":"Reed","salary":61000,"department_id":"D3022"}
]Employee 22 has three snapshots and the top salary row is the current one.
Constraints