# Badge SQL エラー: q.user\_id

**URL:** <https://meta.discourse.org/t/badge-sql-error-q-user-id/86640>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [2018 年 5 月 2 日午後 9:13 UTC](https://meta.discourse.org/t/badge-sql-error-q-user-id/86640 "2018-05-02T21:13:22Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![hross](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@hross](https://meta.discourse.org/u/hross)\
**Post date:** [2018 年 5 月 2 日午後 9:13 UTC](https://meta.discourse.org/t/badge-sql-error-q-user-id/86640/1 "2018-05-02T21:13:22Z")

</div>

こんにちは！

「Solutions checkbox」プラグインを使って、回答が解決としてマークされたユーザー向けのバッジを作成しようとしています。これが SQL クエリです：

```
SELECT
       u.username AS "username",
       count(*) AS "count_received_best_answer",
       current_timestamp granted_at
FROM
       notifications n
JOIN
       users u ON n.user_id = u.id
JOIN
       topics t ON n.topic_id = t.id
JOIN
       categories c ON t.category_id = c.id
WHERE
       n.notification_type = 14 AND
       n.data LIKE '%solved.accepted_notification%' AND 
       n.created_at > CURRENT_DATE - INTERVAL '30 days'
GROUP BY u.username
HAVING count(*) > 0
ORDER BY count(*)

```

ただし、バッジをプレビューしようとすると、以下のエラーが表示されます：

 ![23%20PM](https://global.discourse-cdn.com/meta/original/3X/7/6/76a7989fbd435cf5b2277666a2a873ebb1607a1f.png)

ここでの検索から、q.user\_id はこれらのバッジジョブの裏側にあるフィールドであると推測できましたが、なぜこのエラーが発生しているのか分かりません。ご協力いただけますと幸いです！

---

_[View the full topic](https://meta.discourse.org/t/badge-sql-error-q-user-id/86640)._
