Ruby On Rails、Postgresql - Date_Part 或每分钟组提取

Ruby On Rails, Postgresql - Date_Part or Extract for every minute group

我正在寻找一种方法来获取每分钟记录的分组输出。我正在寻找看起来像这样的结果:

{"2015-01-05 12:05" => 5, "2015-01-05 12:06" => 2}

当使用 DATE_PARTEXTRACT 我得到这个作为结果

{0.0=>1, 48.0=>2, 23.0=>3, 42.0=>2, 47.0=>2, 54.0=>1, 46.0=>2, 2.0=>1, 44.0=>2, 45.0=>2, 53.0=>1, 6.0=>3, 49.0=>1, 56.0=>2, 22.0=>1, 51.0=>1, 43.0=>2, 24.0=>2, 5.0=>1, 7.0=>1, 37.0=>2, 33.0=>2, 50.0=>1, 1.0=>2}

这是我的代码:

Model.group("DATE_PART('minute', created_at)").count
Model.group("EXTRACT(MINUTE FROM created_at)").count
Model.group("to_char(created_at,'YYYY-MM-DD HH24:MI')").count