lundi 26 septembre 2016

Check if two different values appear successively in a table in SQL?

There's a table that looks like this (there are more columns, but not relevant to the query):

DocumentId | DocumentStateId | TransitionMoment
111222       -2                2016-04-21
111222       -1                2016-04-22
111222       -7                2016-04-23
111222       -5                2016-04-24
111222       -6                2016-04-25
111222       -1                2016-04-26
333141       -2                2016-05-01
333141       -7                2016-05-09
333141       -6                2016-05-10
333141       -3                2016-05-15
777525       -1                2016-02-10
777525       -6                2016-02-10
777525       -7                2016-02-10
777525       -5                2016-02-10
777525       -2                2016-02-10

What options do I have to check whether a document has went from state "-7" to state "-6" consecutively (without transitioning through other states in between)? In the example Document no. 33141.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire