13.3 1 Day Retention


#1

This is my code

select
date(g1.created_at) as dt,
round(100 * count(distinct g2.user_id) as retained_users /
count(distinct g1.user_id) as total_users) as retention
from gameplays as g1
left join gameplays as g2 on
g1.user_id = g2.user_id
and date(g1.created_at) = date(datetime(g2.created_at, '-1 day'))
group by 1
order by 1
limit 100;

and my error message is 'Error: near line 1: near "as": syntax error'
But it seems that there is no error near line 1
I want to finish this course overcoming this last hurdle.
Help me.


#2

You have 'count(distinct g1.user_id) as total_users) as retention' when it should be 'count(distinct g1.user_id)) as retention'
Hope this helps!
select
date(g1.created_at) as dt,
round(100 * count(distinct g2.user_id) /
count(distinct g1.user_id)) as retention
from gameplays as g1
left join gameplays as g2 on
g1.user_id = g2.user_id
and date(g1.created_at) = date(datetime(g2.created_at, '-1 day'))
group by 1
order by 1
limit 100;


#3

Thanks much. I was wondering if i had to insert only the column names withing the count() function.