with tmp as (select distinct player_id , event_date, games_played,
lag(event_date,1) over (partition by player_id order by event_date) as lag2,
rank()over(partition by player_id order by event_date) as login_times
from activity)
select round(count(distinct player_id) / (select count(distinct player_id) from activity),2) as fraction from tmp
where timestampdiff(day,lag2,event_date) =1 and login_times=2
尝试使用窗口函数来解。
其他简单方式可参照:https://pallavismile9.medium.com/sql-leetcode-550-game-play-analysis-iv-a3920e2a521f