- ALWAYS initialize user variables, by default they are NULL.
SET @prevID:=@runSum:=0;
UPDATE teamrank t
JOIN members m USING ( teamID )
SET rank =
IF( @prevID != m.teamID,
( @runSum := m.rank ) + ((@prevID := m.teamID)*0),
( @runSum := @runSum + m.rank)
)
ORDER BY t.teamID
;
I made the assumption that the logic needed to complete a team rank is the sum of the ranks for individuals in a team.
The same technique allows you to execute any current amount or counter that should be reset when the "group" changes.
- J -