Postgresqlのnavicatで問題なく動作する次のpostgresqlステートメントがあります。
SELECT date_trunc('day', updated_at), count(*) as total_count
FROM "persons"
WHERE ("persons"."updated_at" BETWEEN '2012-10-17 00:00:00.000000' AND '2012-11-07 12:25:04.082224')
GROUP BY date_trunc('day',updated_at)
ORDER BY count(updated_at) DESC
次のような期待される結果が得られます
2012-10-31 00:00:00,5
2012-11-06 00:00:00,2
2012-11-05 00:00:00,1
これを RoR プロジェクト用に Ruby に変換する必要があります
私はこの声明を次のように書きました
persons = where(updated_at: start.beginning_of_day..Time.zone.now)
persons = persons.group("date(updated_at)")
persons = persons.select("updated_at, count(*) as total_count")
persons = persons.order("count(updated_at)")
ただし、次のエラーが表示されます
PG::Error: ERROR: column "persons.updated_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT updated_at, count(*) as total_count FROM "persons" WH...
^
: SELECT updated_at, count(*) as total_count FROM "persons" WHERE ("persons"."updated_at" BETWEEN '2012-10-17 00:00:00.000000' AND '2012-11-07 14:38:54.674684') GROUP BY date(persons.updated_at) ORDER BY count(updated_at)
私が間違っていることについてのアイデアはありますか?