徽章 SQL 错误:q.user_id

你好!

我正在为那些帖子通过“解决方案复选框”插件被标记为解决方案的用户创建一个徽章。这是 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(*)

然而,当我尝试预览徽章时,出现了以下错误:

通过在此处搜索,我了解到 q.user_id 是这些徽章作业后台中的一个字段,但我无法弄清楚为什么会出现这个错误。感谢任何帮助!

Your query needs to return at least the following columns:

  • user_id
  • granted_at

Also, you should definitely take a look at Add Badge to Solve answer - #2 by dax. :wink:

4 个赞

YES. That was all I needed. Not sure why staring at it for four hours did not make it obvious. thanks much @gerhard

1 个赞

How does this differ from the Add Badge to Solve answer topic? I am looking to do the same thing but unsure if either one would be applied for every solution or a set number?

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