题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
--解决方案(1) WITHt1AS(SELECT*, ROW_NUMBER() OVER(PARTITIONBYplayer_idORDERBYevent_date) rwFROMActivity), t2AS(SELECTevent_date, COUNT(*) installsFROMt1WHERErw=1GROUPBYevent_date), t3AS(SELECTst2.event_date, COUNT(*) installsFROMt1st1JOINt1st2ONst1.player_id=st2.player_idANDst1.rw=1ANDst2.rw=2ANDDATEDIFF(st2.event_date, st1.event_date) =1GROUPBYst2.event_date) SELECTt2.event_dateinstall_dt, t2.installs, FORMAT(IF(t3.event_dateISNULL, 0, t3.installs) /t2.installs, 2) +0Day1_retentionFROMt2LEFTJOINt3ONDATEDIFF(t3.event_date, t2.event_date) =1ORDERBYt2.event_date--解决方案(2) SELECTfirst_dayasinstall_dt, count(DISTINCTplayer_id) asinstalls, ROUND( (SUM(if(datediff(event_date, first_day) =1, 1, 0))) / (count(DISTINCTplayer_id)), 2 ) asDay1_retentionFROM( SELECTplayer_id, event_date, MIN(event_date) over(partitionbyplayer_id) asfirst_dayFROMActivity) aGROUPBYfirst_day