Subject | SELECT FIRST N BY GROUP |
---|---|
Author | |
Post date | 2019-08-07T12:26:45Z |
Good day. I wish to be able to select the n most recent rows by a group. e.g. from the table below I want to select the two most recent salaries for each employee ID ordered by effective date for each EMPID
---------------------------------------
SALARIES TABLE
---------------------------------------
ID EMPID SALARY EFFDATE
1 25 100 01/04/17
2 30 150 01/04/17
3 25 200 01/04/18
4 30 250 01/04/18
5 30 350 01/04/19
6 22 100 01/04/18
7 25 300 01/04/19
The result should be
ID EMPID SALARY EFFDATE
6 22 300 01/04/18
7 25 300 01/04/19
3 25 200 01/04/18
5 30 350 01/04/19
4 30 250 01/04/18