我有一个列utc_time
,其中存储了unix时间戳,
我希望按日期分组,
但是有错误。
def self.memory_info_daily(test_id=1)
self.unscoped
.where{ name =~ 'MemoryInfo' }
.where{ sony_alarm_test_id.eq(test_id)}
.group("to_char(to_timestamp(utc_time), 'YYYY-MM-DD')")
但它的工作原理是在查询结尾附加.count
。
SELECT "sony_alarm_logs".* FROM "sony_alarm_logs" WHERE "sony_alarm_logs"."name" ILIKE 'MemoryInfo' AND "sony_alarm_logs"."sony_alarm_test_id" = 1 GROUP BY to_char(to_timestamp(utc_time), 'YYYY-MM-DD')
E, [2014-06-27T16:17:14.379965 #29797] ERROR -- : PG::GroupingError: ERROR: column "sony_alarm_logs.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "sony_alarm_logs".* FROM "sony_alarm_logs" WHERE "so...
^