# 特定のカテゴリの閲覧履歴を確認する

**URL:** https://meta.discourse.org/t/read-history-for-a-particular-category/226740
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [2019 年 3 月 19 日午前 8:04 UTC](https://meta.discourse.org/t/read-history-for-a-particular-category/226740 "2019-03-19T08:04:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Cozdabuch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cozdabuch/32/139120_2.png) [@Cozdabuch](https://meta.discourse.org/u/Cozdabuch)
#### Post date: [2019 年 3 月 19 日午前 8:04 UTC](https://meta.discourse.org/t/read-history-for-a-particular-category/226740/1 "2019-03-19T08:04:37Z")

</div>

> [@vinothkannans](#):
>
> SELECT tu.topic\_id, tu.last\_read\_post\_number FROM topics LEFT OUTER JOIN topic\_users AS tu ON topics.id = tu.topic\_id WHERE topics.category\_id = 4 AND tu.user\_id = 1 AND tu.last\_visited\_at IS NOT NULL

この特定のクエリを以下のように記述する方法はありますか？

- カテゴリー ID 34 のトピックで、グループ「executive\_board」に所属していないユーザーが閲覧したものを対象とする
  - ユーザーを表示、トピックを表示、閲覧日時を表示する。

---

<div class="post-metadata">

### Author: ![Cozdabuch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cozdabuch/32/139120_2.png) [@Cozdabuch](https://meta.discourse.org/u/Cozdabuch)
#### Post date: [2022 年 5 月 11 日午前 3:53 UTC](https://meta.discourse.org/t/read-history-for-a-particular-category/226740/2 "2022-05-11T03:53:08Z")

</div>

面白いことに、これは自動的に更新されました。そして、誰かが答えを持っていると私が望むほど、再び関連性があります。

---

<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: [2022 年 5 月 11 日午前 10:21 UTC](https://meta.discourse.org/t/read-history-for-a-particular-category/226740/3 "2022-05-11T10:21:02Z")

</div>

はい、この件についてはしばらくお待ちいただいていたようですね。🙂

このようなもので対応できるかと思います。（`group_id = 3` の部分を、executive\_board の `group_id` に置き換える必要があります）

```plaintext
SELECT tu.user_id,
       tu.topic_id,
       tu.last_read_post_number,
       tu.last_visited_at AS read
FROM topics t
LEFT OUTER JOIN topic_users tu ON t.id = tu.topic_id
WHERE tu.user_id NOT IN (SELECT user_id
    FROM group_users
    WHERE group_id = 3)
AND t.category_id = 34
AND tu.last_visited_at IS NOT NULL
ORDER BY tu.last_visited_at DESC

```

---

<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: [2022 年 6 月 10 日午前 10:21 UTC](https://meta.discourse.org/t/read-history-for-a-particular-category/226740/4 "2022-06-10T10:21:38Z")

</div>

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