I have a table events
as follows:
f_id leg
1 1
2 1
3 1
4 2
5 2
6 3
7 1
8 1
9 2
I want a running total of every time the leg
changes. Expected output:
f_id leg total_legs
1 1 1
2 1 1
3 1 1
4 2 2
5 2 2
6 3 3
7 1 4
8 1 4
9 2 5
Not sure how to go about this.
SELECT *, @leg_var:=IF(@current_leg=leg, leg) as total_legs FROM `events`
This is clearly wrong.