# 查找获得最多标记的用户

**URL:** <https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [2020年九月14日 07:53 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931 "2020-09-14T07:53:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)\
**Post date:** [2020年九月14日 07:53 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/1 "2020-09-14T07:53:19Z")

</div>

大家好 😀

我对查询并不是特别精通。我需要的是按通过审核的标记数量（即被标记且经版主批准的数量）从高到低排列的用户名列表，并以如下示例格式展示：

| 用户名 | 标记数量 |
| --- | --- |
| Discourse\_test | 12 |
| Testing | 9 |
| Bob | 4 |
| Aaron15 | 1 |

如果有人能帮忙，我将不胜感激。

---

<div class="post-metadata">

**Author:** ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)\
**Post date:** [2020年九月14日 10:42 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/4 "2020-09-14T10:42:35Z")

</div>

非专业人士，仅供参考：

```sql
SELECT u.username "Username", COUNT(pa.agreed_at) "Flag Count"
FROM post_actions pa
JOIN posts p ON pa.post_id = p.id
JOIN users u ON p.user_id = u.id
WHERE pa.agreed_at IS NOT NULL
GROUP BY u.username
ORDER BY "Flag Count" DESC

```

---

<div class="post-metadata">

**Author:** ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)\
**Post date:** [2020年九月14日 10:51 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/5 "2020-09-14T10:51:10Z")

</div>

我会试试的。谢谢 @Arkshine 🤩

---

<div class="post-metadata">

**Author:** ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)\
**Post date:** [2020年九月14日 17:06 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/6 "2020-09-14T17:06:02Z")

</div>

试了一下，效果非常好。旗帜数量顺序不对并不是大问题，我可以接受。再次感谢！

---

<div class="post-metadata">

**Author:** ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)\
**Post date:** [2020年九月14日 17:20 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/7 "2020-09-14T17:20:23Z")

</div>

我已在上面更新了 SQL。

---

<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:** [2020年十二月30日 12:08 UTC](https://meta.discourse.org/t/find-users-with-highest-number-of-flags/163931/8 "2020-12-30T12:08:05Z")

</div>

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