LeetCode--550. 遊戲玩法分析 IV

2020-10-07 12:01:05

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-4je0AEbt-1601946503579)(3AD77A59E7624D96A5E90B84C3254C3C)][外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-mqKQfcjE-1601946503582)(B9840267DFA44885B6240CBEBA9041D6)]

建表

create table activity
(
player_id int,
device_id int,
event_date date,
games_played int
);
insert into activity values(1, 2, '2016-03-01', 5);
insert into activity values(1, 2, '2016-05-02', 6);
insert into activity values(1, 3, '2017-06-25', 1);
insert into activity values(3, 1, '2016-03-02', 0);
insert into activity values(3, 4, '2018-07-03', 5);

思路:

得出所有玩家次日登入時間,看在原資料中是否存在,統計存在的個數,除以總人數。

select
	ROUND(COUNT(DISTINCT player_id)/(select COUNT(DISTINCT player_id) FROM Activity), 2) AS fraction
from
    Activity
where
	(player_id,event_date)
	in
	(select player_id, Date(min(event_date)+1) from Activity GROUP BY player_id);