Best way to count records by arbitrary time intervals in Rails+Postgres
问题 My app has a Events table with time-stamped events. I need to report the count of events during each of the most recent N time intervals. For different reports, the interval could be \"each week\" or \"each day\" or \"each hour\" or \"each 15-minute interval\". For example, a user can display how many orders they received each week, day, or hour, or quarter-hour. 1) My preference is to dynamically do a single SQL query (I\'m using Postgres) that groups by an arbitrary time interval. Is there