# Badges for 10 and 100 wiki edits across topics

**URL:** <https://meta.discourse.org/t/badges-for-10-and-100-wiki-edits-across-topics/291287>\
**Category:** Data & reporting\
**Tags:** wiki-posts, sql-triggered-badge\
**Created:** [January 11, 2024, 9:40am UTC](https://meta.discourse.org/t/badges-for-10-and-100-wiki-edits-across-topics/291287 "2024-01-11T09:40:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [January 11, 2024, 6:58pm UTC](https://meta.discourse.org/t/badges-for-10-and-100-wiki-edits-across-topics/291287/2 "2024-01-11T18:58:56Z")

</div>

I’ve been playing with this kind of format to avoid the `MIN`/`MAX` issue of ascribing the wrong `granted_at` date when bringing a badge in ‘mid-flow’ (they tend to work better when people haven’t already achieved the criteria before the badge is introduced).

So possibly something like this:

```sql
SELECT 
    user_id,
    created_at granted_at
FROM (
    SELECT 
        pr.user_id,
        pr.created_at,
        ROW_NUMBER() OVER (PARTITION BY pr.user_id ORDER BY pr.created_at) as row_number
    FROM post_revisions pr
    INNER JOIN badge_posts p ON p.id = pr.post_id
    WHERE p.wiki = TRUE
      AND pr.hidden = FALSE
      AND pr.user_id > 0
) AS revisions
WHERE row_number = 100

```

(I’ve not included the usual ‘don’t include deleted topics or posts’ as edits to old wikis should probably still count. I’ve not added the backfill either, but I think this one would be ‘update daily’ as the trigger?)

---

_[View the full topic](https://meta.discourse.org/t/badges-for-10-and-100-wiki-edits-across-topics/291287)._
