当前位置:网站首页>SQL | some indicators of the game industry
SQL | some indicators of the game industry
2022-06-11 03:25:00 【Cherish the wood】
Game data background “ Log in ” and “ Log out ” Two tables .
among ,“ role id” Field uniquely identifies the player .
Two days before opening the game (2022-08-13 to 2022-08-14) The login log and logout log of are as follows
Log in 
Log out 
1、 First day of service (2022-08-13), Game DAU And the retention rate of the next day
select count(distinct t1. role id) as DAU, count(distinct t2. role id)/count(distinct t1. role id) as Next day retention rate
from (select * from Log in where date ='2022-08-13') t1
left join
(select * from Log in where date ='2022-08-14') t2
on t1. role id=t2. role id

2、 On the first day of service opening (2022-08-13) Grade distribution , That is, the number of characters in each level
select role id, Role level
from (select *,rank() over(partition by role id order by Time desc) rk
from (select date , The login time as Time , role id, Role level
from Log in
where date ='2022-08-13'
union all
select date , Logout time as Time , role id, Role level
from Log out
where date ='2022-08-13') t1
) t2
where rk=1

3、 On the first day of service opening (2022-08-13) Level stagnation rate .
( Level stagnation rate = The number of characters staying at this level / The total number of people who have reached this level ; If the player does not log out of the log , Then use the level information of the login log .)
WITH a as
(select Role level ,count(distinct role id) as co
from (select date , The login time as Time , role id, Role level
from Log in
where date ='2022-08-13'
union all
select date , Logout time as Time , role id, Role level
from Log out
where date ='2022-08-13') t1
group by Role level
),
b as
(select Role level ,count(*) as co
from (select *,rank() over(partition by role id order by Time desc) rk
from (select date , The login time as Time , role id, Role level
from Log in
where date ='2022-08-13'
union all
select date , Logout time as Time , role id, Role level
from Log out
where date ='2022-08-13') t1
) t2
where rk=1
group by Role level
)
select a. Role level as role ,ifnull(b.co/a.co,0) as Role stagnation rate
from a left join b on a. Role level =b. Role level
order by a. Role level

4、 Please according to the time when players log in and out , Count the total online time of each player every day .
( If there is no corresponding log out after the player logs in , You can use the same day 23:59:59 As the logout time , The calculation between times can consider using the timestamp function unix_timestamp.) Here I directly use timestampdiff, Choose according to your needs day\minute\second etc.
select t1. date ,t1. role id,sum(timestampdiff(second,t1. The login time ,ifnull(t2. Logout time ,concat(t1. date ,'23:59:59')))/60) as ' Duration /min'
from (select *,rank() over(partition by role id order by The login time ) rk
from Log in ) t1
left join
(select *,rank() over(partition by role id order by Logout time ) rk
from Log out ) t2
on t1. role id=t2. role id and t1.rk=t2.rk and t1. date =t2. date
group by t1. date ,t1. role id
order by t1. date ,t1. role id

5、 Please according to the time when players log in and out , Count the distribution of online hours of each player on the first day of service opening .
( If there is no corresponding log out after the player logs in , You can use the same day 23:59:59 As the logout time , The calculation between times can consider using the timestamp function unix_timestamp.【 Distinguish between online time periods :0-30min,30min-1h,1-2h,>2h】
select Duration distribution ,count(*) as Number of players
from
(select *,
(case when min<=30 then '0-30min'
when min>30 and min<=60 then '30min-1h'
when min>60 and min<=120 then '1-2h'
else '>2h' end) as ' Duration distribution '
from (select t1. date ,t1. role id,sum(timestampdiff(second,t1. The login time ,ifnull(t2. Logout time ,concat(t1. date ,'23:59:59')))/60) min
from (select *,rank() over(partition by role id order by The login time ) rk
from Log in
) t1
left join
(select *,rank() over(partition by role id order by Logout time ) rk
from Log out
) t2
on t1. role id=t2. role id and t1.rk=t2.rk and t1. date =t2. date
group by t1. date ,t1. role id
) t3
)t4
group by Duration distribution

边栏推荐
- Unity之数据持久化——Json
- HQChart实战教程55-欧易网K线面积图
- Detailed explanation of unity project optimization (continuous supplement)
- Xu Li 618, how can Suning fight this hard battle?
- TweenMax五彩小球弹跳动画
- TimeHelper
- Start QQ through the program to realize automatic login
- Instructor add function_ Enable auto fill_ Instructor modification function
- JSCPCP L. Collecting Diamonds(思维)
- cv. Houghcircles: Circular Hough transform opencv
猜你喜欢

MySQL learning notes: JSON nested array query

Harris corner detection opencv

In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May

Unity之数据持久化——Json

【ELT.ZIP】OpenHarmony啃论文俱乐部——数据高通量无损压缩方案

Troubleshooting of single chip microcomputer communication data delay

cv. Matchtemplate image model matching opencv

Free flying animation of paper plane based on SVG

postgresql源码学习(十七)—— MVCC②-快照与隔离级别简介

ASLR
随机推荐
File compositor
Azure Kubernates Service 更新|提升开发体验和效率
postgresql 函数的参数为自定义类型时传参格式
three.js炫酷科技感背景h5动画
Vocabulary Construction -- code completion fast food tutorial (3) - word segmentation
用Fragment实现图片简易浏览
023 MySQL索引优化口诀-索引失效的常见情况
【ELT.ZIP】OpenHarmony啃论文俱乐部——快速随机访问字符串压缩
File file = new file ("test.txt") file path
PostgreSQL source code learning (22) - fault recovery ③ - transaction log registration
C language pointer
Multi thread alternate output ab
RequestContextHolder
Troubleshooting of single chip microcomputer communication data delay
[safety science popularization] have you been accepted by social workers today?
The dependent version number in the dependencymanagement in the POM project parent in the idea is red
ArTalk | 如何用最小投入,构建国产超融合进化底座?
Using minted to insert highlighted code in texstudio in latex environment
潮玩力真火力!年轻人第一台巨幕影院?酷开电视Max 86“庞然来袭
Promise使用