Skip to content

Instantly share code, notes, and snippets.

@timkeller
Created March 2, 2012 13:10
Show Gist options
  • Save timkeller/1958298 to your computer and use it in GitHub Desktop.
Save timkeller/1958298 to your computer and use it in GitHub Desktop.
For a simple user awards system: Show all users who received more than 3 awards in a single calendar week. Exclude awards that have already been issued.
SELECT user_id,
COUNT(*) AS num,
date_format(creation_date, '%Y%u') AS theweek,
FROM awards
WHERE issued = 0
GROUP BY user_id, theweek
HAVING num >= 3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment