1、题目描述
For the player with id 1, 5 + 6 = 11 games played by 2016-05-02, and 5 + 6 + 1 = 12 games played by 2017-06-25.
For the player with id 3, 0 + 5 = 5 games played by 2018-07-03.
Note that for each player we only care about the days when the player logged in.
来源:力扣(LeetCode)
2、解题思路
1# 定义连个变量@i
作为games_played_so_far
累计,@j:=player_id
2# 利用@j=(@j:=player_id)
的判断结果(真为1,假为0)对@i
清零
3、提交记录
select player_id,event_date,round((@i:=@i*(@j=(@j:=player_id))+games_played),0) as games_played_so_far
from Activity,(select @i:=0,@j:=0) b
order by player_id,event_date