# 過去の課題を検索

**URL:** <https://meta.discourse.org/t/searching-for-historical-assignments/228716>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [2022 年 6 月 1 日午前 9:10 UTC](https://meta.discourse.org/t/searching-for-historical-assignments/228716 "2022-06-01T09:10:14Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Colin\_Mueller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/colin_mueller/32/220223_2.png) [@Colin\_Mueller](https://meta.discourse.org/u/Colin_Mueller)\
**Post date:** [2022 年 6 月 1 日午後 7:31 UTC](https://meta.discourse.org/t/searching-for-historical-assignments/228716/6 "2022-06-01T19:31:02Z")

</div>

素晴らしい @michebs – 助けてくれてありがとう！

今日中に似たようなクエリをなんとか作成し始めていたのですが（`post_custom_fields` テーブルを見つけたときは驚きました）、あなたのクエリの方が最終的には **はるかに** きれいです。

トピックが直接再割り当てされた場合（解除してから割り当てられたのではなく）に一部のエントリが欠落していることに気づいたので、これを考慮するために `WHERE` 条件を少し変更しました。最終的に以下のようになりました。

```plaintext
SELECT 
    pcf.value AS group,
    p.topic_id,
    p.user_id AS "assigned_by_user_id",
    pcf.created_at::date
FROM posts p
INNER JOIN post_custom_fields pcf ON pcf.post_id = p.id
WHERE (action_code = 'assigned_group' OR action_code = 'reassigned_group') 
    AND pcf.name = 'action_code_who'
ORDER BY pcf.value, pcf.created_at DESC

```

改めて、ご協力ありがとうございました。❤

---

_[View the full topic](https://meta.discourse.org/t/searching-for-historical-assignments/228716)._
