I have a table which records a series of values, as so …
ID. VAL
1. 18
2. 18
3. 20
4. 20
5. 18
I’m trying to work out how to select the records at which the series changes (e.g. Record 1, 3 and 5). I’m using rails, but I’m guessing raw MySQL might be the way forward.
Would appreciate any help you could offer…
Assuming your table looks like this:
What you want to do is self join it against itself, like this:
Such that we join a record with the one preceding it. If the values for the two records differ – we have our answer.