I have a salary table that has a record for every person for every payrun. Even if your salary never changes a new record is posted to this table each payrun with the effective date of that payroll
I want to return the records from this table so that just one record per salary per person with a date denoting when the salary started.
But there is one caveat. If your salary changes then reverts back to the old salary I want two records for that salary for that person.
Sample Data in the table
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/4/2001 50000
8682 12/18/2001 50000
8682 12/28/2001 52000
8682 1/7/2002 52000
8682 1/29/2002 50000
My desired results
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/28/2001 52000
8682 1/29/2002 50000
My initial stab was
select EID,min(Start_Date),Salary from payruns
where EID='8682'
group by EID,Salary
I can't use min start date because the min start date will drop the return to 50000 salary.
It just returns:
My desired results
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/28/2001 52000
Losing the fact the salary returned to 50000 in 2002.
Any thoughts?
I want to return the records from this table so that just one record per salary per person with a date denoting when the salary started.
But there is one caveat. If your salary changes then reverts back to the old salary I want two records for that salary for that person.
Sample Data in the table
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/4/2001 50000
8682 12/18/2001 50000
8682 12/28/2001 52000
8682 1/7/2002 52000
8682 1/29/2002 50000
My desired results
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/28/2001 52000
8682 1/29/2002 50000
My initial stab was
select EID,min(Start_Date),Salary from payruns
where EID='8682'
group by EID,Salary
I can't use min start date because the min start date will drop the return to 50000 salary.
It just returns:
My desired results
EID Start_Date Salary
8682 11/6/2001 50000
8682 12/28/2001 52000
Losing the fact the salary returned to 50000 in 2002.
Any thoughts?