clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3799316 fiddles created (41678 in the last week).

CREATE TABLE activity ( `player_id` INTEGER, `device_id` INTEGER, `event_date` VARCHAR(10), `games_played` INTEGER ); INSERT INTO activity (`player_id`, `device_id`, `event_date`, `games_played`) VALUES ('1', '2', '2016-03-01', '5'), ('1', '2', '2016-05-02', '6'), ('1', '3', '2017-06-25', '1'), ('3', '1', '2016-03-02', '0'), ('3', '4', '2018-07-03', '5');
 hidden batch(es)


select a1.player_id, a1.event_date,a2.player_id, a2.event_date from activity as a1 inner join activity as a2 on a1.event_date >= a2.event_date and a1.player_id = a2.player_id
player_id event_date player_id event_date
1 2017-06-25 1 2016-03-01
1 2016-05-02 1 2016-03-01
1 2016-03-01 1 2016-03-01
1 2017-06-25 1 2016-05-02
1 2016-05-02 1 2016-05-02
1 2017-06-25 1 2017-06-25
3 2018-07-03 3 2016-03-02
3 2016-03-02 3 2016-03-02
3 2018-07-03 3 2018-07-03
 hidden batch(es)


select a1.player_id, a1.event_date, sum(a2.games_played) as games_played_so_far from activity as a1 inner join activity as a2 on a1.event_date >= a2.event_date and a1.player_id = a2.player_id group by a1.player_id, a1.event_date ORDER BY a1.player_id, a1.event_date
player_id event_date games_played_so_far
1 2016-03-01 5
1 2016-05-02 11
1 2017-06-25 12
3 2016-03-02 0
3 2018-07-03 5
 hidden batch(es)