below is data table :
/* TableName:Data */
id | speed
----------------
1 | 3
2 | 0
3 | 0
4 | 5
5 | 6
6 | 7
7 | 0
8 | 0
9 | 0
10 | 3
N | 2
I want to have a result (with out repeat zero speed) , and specify state of moving ; example :
if first speed row is zero Remove it from result else show with state=START/MOVE
if speed is zero on first row after move state then set state=STOP
if speed is repeat with zero value Remove it from result
after zero value of speed if speed not zero then set state=START
Example Results:
/* Results */
id | speed | status
-------------------------
1 | 3 | START/MOVE
2 | 0 | STOP
4 | 5 | START
5 | 6 | MOVE
6 | 7 | MOVE
7 | 0 | STOP
10 | 3 | START
N | 2 | MOVE
Tested and working.
I’d show a SQLFiddle Demo, but unfortunately, their site is down at the moment.