Skip to content
Advertisement

Find how many times the department of an employee has changed

I have the following table Employee storing any updates made on an employee:

I want to count how many times each employee has changed his department knowing that the employee life cycle is like below : Recuited – IN – OUT and the employees that left the company then went back to it like in this example.

Advertisement

Answer

I’m not sure what “Recruited”, “In” and “Out” have to do with this. If each row represents a period of time when an employee was in a department, then use lag() to measure changes:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement