# Badge based on link stats?

**URL:** <https://meta.discourse.org/t/badge-based-on-link-stats/29018>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [20 Maggio 2015, 2:56am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018 "2015-05-20T02:56:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [20 Maggio 2015, 4:17am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/3 "2015-05-20T04:17:30Z")

</div>

[https://meta.discourse.org/badges/124/popular-link](https://meta.discourse.org/badges/124/popular-link)

SQL

```plaintext
select l.user_id, post_id, min(l.created_at) granted_at
from topic_links l
join posts p on p.id = post_id and p.deleted_at IS NULL
join topics t on t.id = p.topic_id and t.deleted_at IS NULL and t.archetype <> 'private_message'
where not internal and clicks >= 50
group by l.user_id, l.post_id

```

@codinghorror I don’t mind adding this in for current release … seems pretty simple, your call

---

_[View the full topic](https://meta.discourse.org/t/badge-based-on-link-stats/29018)._
