尝试:
WITH t as ( SELECt time_series as trunc FROM generate_series('2013-02-27 22:00'::timestamp, '2013-02-28 2:00', '1 hour') as time_series)SELECt DISTINCT ON(t.trunc) t.trunc, e.id FROM t JOIN event e ON e.created < t.trunc ORDER BY t.trunc, e.created DESC如果太慢-告诉我。我会给你一个更快的查询。



