# 阅读时间徽章？

**URL:** https://meta.discourse.org/t/a-badge-for-reading-time/178482
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [2021年二月4日 23:38 UTC](https://meta.discourse.org/t/a-badge-for-reading-time/178482 "2021-02-04T23:38:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cosdesign](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cosdesign/32/208585_2.png) [@cosdesign](https://meta.discourse.org/u/cosdesign)
#### Post date: [2021年二月4日 23:38 UTC](https://meta.discourse.org/t/a-badge-for-reading-time/178482/1 "2021-02-04T23:38:15Z")

</div>

你好！我在 [Codecademy 社区](https://discuss.codecademy.com/badges/128/bookworm-gold) 上看到，他们根据成员阅读时长设置了 3 个徽章。有人知道如何创建类似的徽章吗？

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/d/bda3157f7047f814de5269858ff19d25108ad2e8.png)

目前我受该“阅读者”徽章启发制作了这样一个徽章，但我不清楚这个数字代表什么（在我的情况下，26 是显示我有资格获得该徽章的最大数值）。

```
SELECT user_id, count(*) c, CURRENT_DATE as granted_at
FROM post_timings
GROUP BY user_id
HAVING count(*) >= 26

```

以下是我的统计数据（我感兴趣的总阅读时长）：  
 ![image](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/f/2/f23c8cd30511068c6734a7091a0b3fa6d23c58ca.png)

---

<div class="post-metadata">

### Author: ![michebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michebs/32/190102_2.png) [@michebs](https://meta.discourse.org/u/michebs)
#### Post date: [2021年二月5日 09:47 UTC](https://meta.discourse.org/t/a-badge-for-reading-time/178482/3 "2021-02-05T09:47:15Z")

</div>

此查询列出了阅读帖子超过 480 小时的用户。希望这能帮到您。

```sql
-- 毫秒转换：[小时数 * 3600000]：480 * 3600000 = 1,728,000,000

WITH time_reading AS (
    SELECT 
        user_id, 
        SUM(msecs) AS hours 
    FROM post_timings 
    GROUP BY user_id
    HAVING SUM(msecs) >= 1728000000)

SELECT user_id, CURRENT_TIMESTAMP AS granted_at
FROM time_reading

```

---

<div class="post-metadata">

### Author: ![cosdesign](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cosdesign/32/208585_2.png) [@cosdesign](https://meta.discourse.org/u/cosdesign)
#### Post date: [2021年二月5日 10:00 UTC](https://meta.discourse.org/t/a-badge-for-reading-time/178482/4 "2021-02-05T10:00:37Z")

</div>

您的查询运行正常，非常感谢！🙂

---

<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: [2021年三月7日 10:04 UTC](https://meta.discourse.org/t/a-badge-for-reading-time/178482/6 "2021-03-07T10:04:27Z")

</div>

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