Reputation: 919
select retention
, Sum(count(retention)) over(order by retention desc) as Num_Users_Retained
from (select player_id
, round(init_dtime-create_dtime,0) as retention
from player
where Trunc(Create_Dtime) >= To_Date('2012-jan-01','yyyy-mon-dd')
and init_dtime is not null)
Group by retention
order by retention
This query displays two columns: The first column being the day of this year(day 0 is jan-1,day 259 is today sep-16) and the second column being the retention. Day 0 has 428,000 because all users are retained, Day 1 has 300K (since 128K people didnt log in after their first day), and the number keeps decreasing as time goes on. I want to show another column for the percentages that each day is of day 0. Is that clear enough or should I provide further detail?
Upvotes: 1
Views: 787
Reputation: 27251
select retention
, Num_Users_Retained
, round(Num_Users_Retained/max(Num_Users_Retained) over() * 100, 2) as perc
from (select retention
, Sum(count(retention)) over(order by retention desc) as Num_Users_Retained
from (select player_id
, round(init_dtime-create_dtime,0) as retention
from player
where Trunc(Create_Dtime) >= To_Date('2012-jan-01','yyyy-mon-dd')
and init_dtime is not null
)
Group by retention
order by retention)
order by retention
Upvotes: 2