: SELECT created_at, count(created_at) as count FROM "candidates" GROUP BY date(created_at)
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "candidates.created_at" must appear in the GROUP BY clause or be used in an aggregate function
created_at
是日期时间列
candidates
是一个表格
如何让它发挥作用?感谢。
答案 0 :(得分:2)
问题是您正在选择created_at
作为单独的列。您需要在其周围使用聚合函数(如MIN
或MAX
)或将其添加到GROUP BY
。
由于您已经按date(created_at)
进行分组,因此您可能希望在选择中使用该分组。所以像这样:
SELECT
DATE(created_at),
COUNT(created_at) as count
FROM "candidates"
GROUP BY date(created_at)