【LeetCode刷题】数据库之中等题:534. 游戏玩法分析 III

【LeetCode刷题】数据库之中等题:534. 游戏玩法分析 III_第1张图片
【LeetCode刷题】数据库之中等题:534. 游戏玩法分析 III_第2张图片
解法一:窗口函数

select player_id,event_date,sum(games_played) over(partition by player_id order by event_date) as games_played_so_far
from Activity;

解法二:自联结

select a1.player_id,a1.event_date,sum(a2.games_played) as games_played_so_far
from Activity a1,Activity a2
where a1.player_id=a2.player_id
and a1.event_date>=a2.event_date
group by a1.player_id,a1.event_date

你可能感兴趣的:(LeetCode)