Imagine that I have a table in the database to keep the history of customers' status.
If I want to get customers from for example status 1001 to 1002, it’s simple
Select * from TableName where StartStatus=1001 and EndStatus=1002
If I want to write a query that returns the customers that change from status 1001 to 1005, how can I do that?
The result should be just one record for each customer (I need to omit the internal changes for a customer, for example, do not need 1001 to 1002 and 1002 to 1003 and 1003 to 1004)
For example in this data, the customer with id 2 changed from 1006 to 1005, then the query shouldn't return it

1000 -> 1001 -> 1002 -> 1003 -> 1004 -> 1005. This includes a path from 1001 to 1005. Customer 2's status journey was just1006 -> 1005. This does not include a path from 1001 to 1005