datePostgreSQLであれば、date_trunc
https://www.postgresql.jp/document/9.5/html/functions-datetime.html#functions-datetime-trunc
を実行した列で集約すれば、望みの値が得られるように思います
集約絡みでうまくいかないことがあれば、window functionを使うと多くの問題が解決できると思います
機会があれば挑戦してみてください
(でも、RailsのSQLbuilderは生成してくれないと思います...)
mysqlでは TIME_FORMAT するか TO_SECONDS の剰余を取るほかないようです...
http://sqlfiddle.com/#!9/9eecb7d/69182
SELECT
sec,
FROM_UNIXTIME(sec * 3600 - TO_SECONDS('1970-01-01 00:00:00')) as my_date_time,
count(sec) AS count
FROM (
SELECT
id,
updated_at,
CAST(TO_SECONDS(updated_at) / 3600 AS SIGNED INTEGER) AS sec,
TIME_FORMAT(updated_at, '%Y%m%d%h') AS ymdh
FROM (
SELECT 1 AS id, TIMESTAMP '2016-07-15 00:00:00' AS updated_at FROM DUAL
UNION ALL SELECT 2, TIMESTAMP '2016-07-15 00:01:00' FROM DUAL
UNION ALL SELECT 3, TIMESTAMP '2016-07-15 01:00:00' FROM DUAL
UNION ALL SELECT 4, TIMESTAMP '2016-07-15 01:01:00' FROM DUAL
UNION ALL SELECT 5, TIMESTAMP '2016-07-15 01:02:00' FROM DUAL
UNION ALL SELECT 6, TIMESTAMP '2016-07-15 02:00:00' FROM DUAL
) AS T
) AS T
GROUP BY
sec
ORDER BY
sec
;