1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-0550.test 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-04-20 22:51 . 262-550-1045-1341-1867 (5)
# $550. 游戏玩法分析 IV
# https://leetcode-cn.com/problems/game-play-analysis-iv/
# SQL架构
Create table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int);
Truncate table Activity;
insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-01', '5');
insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-02', '6');
insert into Activity (player_id, device_id, event_date, games_played) values ('2', '3', '2017-06-25', '1');
insert into Activity (player_id, device_id, event_date, games_played) values ('3', '1', '2016-03-02', '0');
insert into Activity (player_id, device_id, event_date, games_played) values ('3', '4', '2018-07-03', '5');
# Write your MySQL query statement below
select
round(avg(a.event_date is not null), 2) as fraction
from
(
select
player_id,
min(event_date) as login
from
Activity
group by
player_id
) tmp
left join Activity a on tmp.player_id = a.player_id
and datediff(a.event_date, tmp.login) = 1;
# clean-up
drop table Activity;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助