# Um resumo de votos por tópico, incluindo tags

**URL:** <https://meta.discourse.org/t/a-summary-of-votes-by-topic-including-tags/256770>\
**Category:** Data & reporting\
**Tags:** topic-voting, sql-query\
**Created:** [Janeiro 26, 2023, 10:35pm UTC](https://meta.discourse.org/t/a-summary-of-votes-by-topic-including-tags/256770 "2023-01-26T22:35:20Z")\
**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:** [Janeiro 27, 2023, 8:04pm UTC](https://meta.discourse.org/t/a-summary-of-votes-by-topic-including-tags/256770/2 "2023-01-27T20:04:38Z")

</div>

Olá e bem-vindo(a) @CarrieSeltzer 🙂

Algo assim funcionaria para você?

```sql
-- [params]
-- int :category_id 

WITH tag_names AS (
    SELECT t.id topic_id,
    string_agg(tags.name, ', ' ORDER BY tags.name) AS "tags"
    FROM topics t
    JOIN topic_tags tt ON tt.topic_id = t.id
    JOIN tags ON tags.id = tt.tag_id
    GROUP BY t.id
)

SELECT t.created_at::date,
       dvtvc.topic_id,
       votes_count,
       t.posts_count,
       tn.tags,
       t.closed
FROM discourse_voting_topic_vote_count dvtvc
JOIN topics t ON t.id = dvtvc.topic_id
LEFT JOIN tag_names tn ON dvtvc.topic_id = tn.topic_id
WHERE t.category_id = :category_id
AND votes_count > 0
ORDER BY t.created_at DESC

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/a/8/fa8829cdb48ad19adfb4af80898a1d20c46b260a.png)

---

_[View the full topic](https://meta.discourse.org/t/a-summary-of-votes-by-topic-including-tags/256770)._
