# A silver badge for \_each\_ 5 bronze badges

**URL:** <https://meta.discourse.org/t/a-silver-badge-for-each-5-bronze-badges/283284>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [October 24, 2023, 3:33pm UTC](https://meta.discourse.org/t/a-silver-badge-for-each-5-bronze-badges/283284 "2023-10-24T15:33:49Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ganncamp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ganncamp/32/106199_2.png) [@ganncamp](https://meta.discourse.org/u/ganncamp)\
**Post date:** [October 24, 2023, 3:33pm UTC](https://meta.discourse.org/t/a-silver-badge-for-each-5-bronze-badges/283284/1 "2023-10-24T15:33:49Z")

</div>

We’ve created a bronze badge, [Users Helping Users](https://community.sonarsource.com/badges/110/users-helping-users), for people trying to help other users. That’s granted manually (in order to tell the difference between attempts at being helpful and "me too"s).

For _each_ 5 bronze badges, we want to award a sliver, [Invaluable](https://community.sonarsource.com/badges/111/invaluable), badge.

The SQL I’ve come up with finds the right two users, but only once each:

```plaintext
SELECT user_id, current_timestamp AS granted_at 
FROM user_badges
WHERE badge_id = 110 -- Users Helping Users
    AND (:backfill OR user_id IN (:user_ids))
GROUP BY user_id
HAVING COUNT(*) >= 5

```

Am I missing some 🪄 magic in my SQL, or does the multiplier happen outside the SQL?

Also, it’s really not clear to me how the math happens so that my two users don’t get new badges every day (this will run on a nightly trigger) even if they haven’t gotten 5 new bronze badges.

Is there a guide to this that my searching didn’t find?

---

_[View the full topic](https://meta.discourse.org/t/a-silver-badge-for-each-5-bronze-badges/283284)._
