gpt4 book ai didi

ruby-on-rails - rails/Postgres : Column must appear in group by clause

转载 作者:行者123 更新时间:2023-11-29 14:12:37 26 4
gpt4 key购买 nike

所以 Postgres 提示:

PGError: ERROR:  column "sessions.created_at" must appear in the GROUP BY clause or be used in an aggregate function

但问题是,“created_at”确实出现在 group by 子句中:

SELECT     created_at, count(id) as visit_count FROM       "sessions"  WHERE     ("sessions"."site_id" IN (4, 3)) AND ("sessions"."created_at" >= '2011-10-20 00:00:00.000000') AND ("sessions"."created_at" <= '2011-10-27 23:59:59.999999') GROUP BY  date(created_at))

这可能与 created_at 被包装在 date() 中有关吗?

提前致谢!

最佳答案

不,它没有出现。

GROUP BY 包含 date(created_at) 而您的 SELECT 列表仅包含 created_at。如果 created_at 是时间戳,那么这是两个不同的东西。

您需要使用 GROUPY BY created_atSELECT date(created_at)(可能是后者)

关于ruby-on-rails - rails/Postgres : Column must appear in group by clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7918052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com