Amending sample Gamification scoring badge

SELECT user_id, current_timestamp AS granted_at 
FROM gamification_scores
WHERE (:backfill OR user_id IN (:user_ids))
GROUP BY 1
HAVING SUM(score) > 9000

Can that query be limited by year, monthly or three months?

1 Like

I think you could add in something like:

SELECT user_id, CURRENT_TIMESTAMP AS granted_at 
FROM gamification_scores
WHERE date >= CURRENT_DATE - INTERVAL '1 MONTH'
  AND user_id > 0
  AND (:backfill OR user_id IN (:user_ids))
GROUP BY 1
HAVING SUM(score) > 1000
1 Like