# Mostrar usuários com mais posts criados usando uma tag

**URL:** https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [23 Abril , 2022 19:46 UTC](https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106 "2022-04-23T19:46:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Senpai](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/senpai/32/257176_2.png) [@Senpai](https://meta.discourse.org/u/Senpai)
#### Post date: [23 Abril , 2022 19:46 UTC](https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106/1 "2022-04-23T19:46:15Z")

</div>

Olá comunidade!

Quero obter os usuários com mais tópicos criados em cada categoria de tag.  
Por exemplo, a lista de usuários com mais posts nesta comunidade usando a tag `data-explorer`.  
Tentei muito com minhas habilidades enferrujadas de SQL, mas não consegui acertar, qualquer ajuda é bem-vinda!

Obrigado desde já 🙂

---

<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: [23 Abril , 2022 21:25 UTC](https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106/2 "2022-04-23T21:25:48Z")

</div>

Isso funcionaria?

```plaintext
-- [params]
-- string :tag_name

SELECT t.user_id,
       count(t.user_id) AS count
FROM topic_tags tt
JOIN topics t ON t.id = tt.topic_id
JOIN tags tg ON tg.id = tt.tag_id
WHERE t.deleted_at IS NULL
AND t.archetype = 'regular'
AND tg.name = :tag_name
GROUP BY t.user_id
ORDER BY count DESC 

LIMIT 10

```

---

<div class="post-metadata">

### Author: ![Senpai](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/senpai/32/257176_2.png) [@Senpai](https://meta.discourse.org/u/Senpai)
#### Post date: [24 Abril , 2022 07:08 UTC](https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106/3 "2022-04-24T07:08:12Z")

</div>

Obrigado @JammyDodger,

Exatamente o que eu estava procurando 🤩

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [24 Maio , 2022 07:08 UTC](https://meta.discourse.org/t/show-top-users-with-most-posts-created-using-a-tag/225106/4 "2022-05-24T07:08:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
