Reputation: 6779
Why would the following query not increment seq?
SELECT @sq :=if(@previous=uid,@sq,0)+1 as seq
,@previous:=uid as user
FROM test
Result:
seq user
1 111
1 111
1 111
1 222
1 222
1 222
Upvotes: 0
Views: 110
Reputation: 56935
You forgot to do set @sq:=0,@previous:=0
at the front?
Alternatively you can always join it in to the query:
SELECT @sq :=if(@previous=uid,@sq,0)+1 as seq
,@previous:=uid as user
FROM test, (select @sq:=0, @previous:=0) foo
Upvotes: 2