Skip to content

Instantly share code, notes, and snippets.

@dpaola2
Last active December 14, 2016 23:16
Show Gist options
  • Save dpaola2/8f067304e6d6c7c6b3f5a543a698a414 to your computer and use it in GitHub Desktop.
Save dpaola2/8f067304e6d6c7c6b3f5a543a698a414 to your computer and use it in GitHub Desktop.
WITH checkpoint_completion_counts AS (
SELECT
COUNT(checkpoint_completions.id) AS checkpoint_completions_count,
checkpoints.ref AS checkpoint_ref,
users.slug
FROM checkpoint_completions
INNER JOIN checkpoints ON checkpoint_completions.checkpoint_ref = checkpoints.ref
INNER JOIN users ON users.id = checkpoint_completions.user_id
GROUP BY 2,3
)
SELECT
*
FROM
checkpoint_completion_counts
WHERE checkpoint_completion_counts.slug = 'user-slug' AND checkpoint_completions_count > 1
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment