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

{"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

关于ruby-on-rails - Ruby On Rails,Postgresql-每分钟组的Date_Part或Extract,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27784610/

10-12 15:37