1 day retention syntax question


#1

Hi – in the 1 day retention lesson (https://www.codecademy.com/courses/sql-analyzing-business-metrics/lessons/common-metrics/exercises/1d-retention-iii?action=lesson_resume&link_content_target=interstitial_undefined)

I want to understand better the syntax of the distinct function in

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;

I originally did it with (count(distinct(g2.user_id)) but was getting errors. Is the space completely interchangeable with the parenthetical, or is it used specifically in cases where there is a join?

Thanks!


#2

DISTINCT is a clause not a function so no parentheses.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.