Created
May 22, 2018 13:19
-
-
Save chrisvaughn/b831de6fd4ce27bbc0050e69b84875d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE streaks | |
SET current_streak = ( | |
CASE | |
WHEN %(date)s - last_checkin_dt = 1 THEN current_streak + 1 | |
ELSE 1 | |
END | |
), | |
longest_streak = GREATEST(longest_streak, ( | |
CASE | |
WHEN %(date)s - last_checkin_dt = 1 THEN current_streak + 1 | |
ELSE 1 | |
END | |
)), | |
last_checkin_dt = %(date)s | |
WHERE user_id = %(user_id)s AND %(date)s > last_checkin_dt | |
RETURNING * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment