LeetCode(数据库)- 游戏玩法分析 V
Posted 程序员牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- 游戏玩法分析 V相关的知识,希望对你有一定的参考价值。
题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1)
WITH t1 AS(SELECT *, ROW_NUMBER() OVER(PARTITION BY player_id ORDER BY event_date) rw FROM Activity),
t2 AS(SELECT event_date, COUNT(*) installs FROM t1 WHERE rw = 1 GROUP BY event_date),
t3 AS(SELECT st2.event_date, COUNT(*) installs FROM t1 st1 JOIN t1 st2 ON st1.player_id = st2.player_id AND st1.rw = 1 AND st2.rw = 2 AND DATEDIFF(st2.event_date, st1.event_date) = 1
GROUP BY st2.event_date)
SELECT t2.event_date install_dt, t2.installs, FORMAT(IF(t3.event_date IS NULL, 0, t3.installs) / t2.installs, 2) + 0 Day1_retention
FROM t2 LEFT JOIN t3 ON DATEDIFF(t3.event_date, t2.event_date) = 1
ORDER BY t2.event_date
-- 解决方案(2)
SELECT
first_day as install_dt,
count(DISTINCT player_id) as installs,
ROUND(
(SUM(if(datediff(event_date, first_day) = 1, 1, 0))) / (count(DISTINCT player_id)), 2
) as Day1_retention
FROM(
SELECT
player_id,
event_date,
MIN(event_date) over(partition by player_id) as first_day
FROM
Activity
) a
GROUP BY
first_day
以上是关于LeetCode(数据库)- 游戏玩法分析 V的主要内容,如果未能解决你的问题,请参考以下文章