Is there a way in MySQL to group “only” connected (serialized) rows in a table:
ex, table:
id user_id score
1 1 100
2 1 100
3 2 100
5 1 100
7 1 100
8 3 100
9 4 100
10 5 100
10 5 100
11 1 100
Group by user_id and sum(score), but only for subsequent lines with the same user_id, the expected results:
user_id score
1 200
2 100
1 200
3 100
4 100
5 200
1 100
Test request:
select t.user_id,sum(t.score)
from table t
group by t.user_id
Will return something like:
user_id score
1 500
2 100
3 100
4 100
5 200
thanks for reference
source
share