题目链接:点击打开链接
题目大意:略。
解题思路:
- 解决方案(1):自变量,算出每一行记录与上一行记录的累加即可
解决方案(2):t1.event_date>=t2.event_date + GROUP BY t1.player_id,t1.event_date 是关键:(自连接)用 t1 比自己还小的所有在 t1.player_id,t1.event_date 范围内的时间,就是到达 t1 时间的总和游戏数
AC 代码
--解决方案(1) SELECTRS.player_id, RS.event_date, RS.games_played_so_farFROM (SELECTplayer_id, event_date, CONVERT( :=IF(<>player_id, games_played, +games_played), SIGNED) games_played_so_far, :=player_idFROMActivity, (SELECT :=0, :=-1) initORDERBYplayer_id, event_date) RS; --解决方案(2) SELECTt1.player_id, t1.event_date, SUM(t2.games_played) games_played_so_farFROMActivityt1,Activityt2WHEREt1.player_id=t2.player_idANDt1.event_date>=t2.event_dateGROUPBYt1.player_id,t1.event_date;