Skip to content

Instantly share code, notes, and snippets.

@geeknees
Last active August 3, 2017 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geeknees/fb81e9b9f5cbb48564ab9d9c63505e7c to your computer and use it in GitHub Desktop.
Save geeknees/fb81e9b9f5cbb48564ab9d9c63505e7c to your computer and use it in GitHub Desktop.
cohort SQL
SELECT count(1) as signed_up_users
FROM users
WHERE users.created_at >= now() - interval 2 day
AND users.created_at < now() - interval 1 day;
SELECT count(distinct lessons.user_id) as logged_in_users
FROM lessons
WHERE lessons.start_date > now() - interval 1 day
AND lessons.start_date < now();
SELECT
count(distinct users.id) as signed_up_users,
count(distinct lessons.user_id) as logged_in_users
FROM users
LEFT JOIN lessons
ON users.id = lessons.user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment