# 当用户访问链接时授予徽章

**URL:** <https://meta.discourse.org/t/grant-badge-when-user-visits-link/276700>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [2023年八月25日 22:55 UTC](https://meta.discourse.org/t/grant-badge-when-user-visits-link/276700 "2023-08-25T22:55:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [2023年八月26日 10:01 UTC](https://meta.discourse.org/t/grant-badge-when-user-visits-link/276700/4 "2023-08-26T10:01:22Z")

</div>

如果它是在特定帖子中共享的特定链接，我认为这个链接可以做到：

```sql
SELECT DISTINCT tlc.user_id, MIN(tlc.created_at) granted_at
FROM badge_posts p
  LEFT JOIN topic_links tl ON tl.post_id = p.id
  LEFT JOIN topic_link_clicks tlc ON tlc.topic_link_id = tl.id
WHERE tl.post_id = 1246
  AND tl.url = 'https://meta.discourse.org/'
  AND tlc.user_id IS NOT NULL
GROUP BY tlc.user_id

```

您需要从特定帖子的 JSON 中获取 `post_id`（或通过数据浏览器进行查找）。

 ![clicky clicky](https://global.discourse-cdn.com/meta/original/4X/7/6/9/769ae8ff0a51f65f075d38689cefffddd309316b.png)

---

_[View the full topic](https://meta.discourse.org/t/grant-badge-when-user-visits-link/276700)._
