Grant a badge based on number of bronze/silver/gold badges

You can use this query for custom member-level badges:

SQL query

SELECT user_id, current_timestamp granted_at 
FROM user_badges  
JOIN badges
On user_badges.badge_id = badges.id
WHERE badges.badge_type_id = 3
GROUP BY user_id 
HAVING count(*) >= 15

badge_type_ids

bronze: 3
silver: 2
gold: 1

Another option if you want to have more than 3 groups of target badges is to collect them in custom sections and then query for badge_grouping_id. E.g. here with 4 Pirate crew ranks:

SQL query

SELECT user_id, current_timestamp granted_at 
FROM user_badges  
JOIN badges
On user_badges.badge_id = badges.id
WHERE badges.badge_grouping_id = 1
GROUP BY user_id 
HAVING count(*) >= 10

badge_grouping_ids

Getting Started: 1
Community: 2
Posting: 3
Trust Level: 4
Other: 5

And then count on for your custom sections…

5 Likes