Ниже для BigQuery Standard SQL и дополнительно оптимизирован для того, чтобы не использовать какие-либо JOIN, а использовать аналитические функции
#standardSQL
SELECT
day,
COUNT(1) total_users,
COUNTIF(delta = 1) retained_users
FROM (
SELECT
day, id,
DATE_DIFF(day, LAG(day) OVER(PARTITION BY id ORDER BY day), DAY) delta
FROM (
SELECT DISTINCT
DATE(created_at) day,
actor.id
FROM `githubarchive.month.201810`
)
)
GROUP BY day
ORDER BY day
или, если использовать исходную запись вопроса:
#standardSQL
SELECT
day,
COUNT(1) total_users,
COUNTIF(delta = 1) retained_users
FROM (
SELECT
day, userID,
DATE_DIFF(day, LAG(day) OVER(PARTITION BY userID ORDER BY day), DAY) delta
FROM (
SELECT DISTINCT
DATE(eventDate) day,
userID
FROM `project.dataset.table`
)
)
GROUP BY day
ORDER BY day