# Использование реакций для выдачи значков

**URL:** <https://meta.discourse.org/t/using-reactions-to-grant-badges/284040>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [30.Октябрь.2023 10:52:17 UTC](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040 "2023-10-30T10:52:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![davidkingham](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/davidkingham/32/119528_2.png) [@davidkingham](https://meta.discourse.org/u/davidkingham)\
**Post date:** [31.Октябрь.2023 17:27:30 UTC](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040/5 "2023-10-31T17:27:30Z")

</div>

Спасибо, это помогло! Вероятно, эту тему стоит перенести в отдельный тред, так как мы уходим от основной темы. Но вот запрос, который я составил (с помощью ChatGPT): он просто возвращает пользователей, поставивших или получивших реакцию, количество реакций, дату реакции и ссылку на конкретный пост. Единственное, что мне не удалось сделать — сделать ссылку на пост кликабельной; похоже, это ограничение касается только ссылок на темы.

```plaintext
WITH reaction_pairs AS (
    SELECT 
      p.user_id AS received_reaction_user_id, 
      dru.user_id AS gave_reaction_user_id, 
      dr.post_id,
      t.id AS topic_id,
      t.slug AS topic_slug,
      p.post_number,
      dru.created_at AS reaction_date
    FROM 
      discourse_reactions_reactions dr
      JOIN discourse_reactions_reaction_users dru ON dr.id = dru.reaction_id
      JOIN posts p ON dr.post_id = p.id
      JOIN topics t ON p.topic_id = t.id
    WHERE 
      dr.reaction_value = 'Your_Specific_Reaction_Here'
)
SELECT 
  ur1.id AS user_id, 
  ur2.username AS "User Who Gave Reaction",
  'Your_Community_URL' || 't/' || rp.topic_slug || '/' || rp.topic_id || '/' || rp.post_number AS "Post URL",
  rp.reaction_date AS "Reaction Date",
  COUNT(*) AS "Number of Reactions"
FROM 
  reaction_pairs rp
  JOIN users ur1 ON rp.received_reaction_user_id = ur1.id
  JOIN users ur2 ON rp.gave_reaction_user_id = ur2.id
GROUP BY 
  ur1.id, 
  ur2.username, 
  rp.topic_slug, 
  rp.topic_id, 
  rp.post_number, 
  rp.reaction_date
ORDER BY 
  "Number of Reactions" DESC, "Reaction Date" DESC

```

---

_[View the full topic](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040)._
