当前位置:网站首页>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
 Insert picture description here
Log out
 Insert picture description here

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

 Insert picture description here

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

 Insert picture description here

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 

 Insert picture description here
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

 Insert picture description here
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 

 Insert picture description here

原网站

版权声明
本文为[Cherish the wood]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110305120192.html