I read about create variable for increment in select in this post select increment counter in mysql
I need some addition to this query.. I need to reset the increment based on user_id.
Sample data :
id user_id name
1 1 A
2 2 B
3 3 C
4 1 D
5 2 E
6 2 F
7 1 G
8 3 H
Expected result:
id user_id name increment
1 1 A 1
4 1 D 2
7 1 G 3
2 2 B 1
5 2 E 2
6 2 F 3
3 3 C 1
8 3 H 2
It's not stop only until 3 increments, if I have more row with user_id
, it will continue the increment.
How do I make query so the output look like that? Thanks!