I have a table T1 with empid, shiftdate and peerid. This stores history of when an employee trained someone. For example, for employee ABCD this is the data I have:
EMPLOYEE|SHIFT_DATE|PEERID
ABCD 05/10/2013 A123
ABCD 05/09/2013 A123
ABCD 05/08/2013 A123
ABCD 05/07/2013 X456
ABCD 05/06/2013 X456
ABCD 05/05/2013 X456
ABCD 05/04/2013 A123
ABCD 05/03/2013 A123
ABCD 05/02/2013 A123
ABCD 05/01/2013 A123
I want to select employee, trainee and trained_since (date). As from the data above some trainees can be repeated over different non-contiguous date/period blocks, so each data period needs to treated as a separate training period, like:
EMPLOYEE|TRAINED_SINCE|TRAINEE
ABCD 05/08/2013 A123
ABCD 05/05/2013 X456
ABCD 05/01/2013 A123
How do I do this? please help.