search for: total_grouped_by_day

Displaying 1 result from an estimated 1 matches for "total_grouped_by_day".

2013 Jan 29
2
Count entries in postgresql grouped by date
...ave a table with visits with a visited_at: attribute which is a datetime field. They seem to be stored as UTC. Now I want to count all visits each day and return something like: { 2013-01-01: 8, 2013-01-02: 4, 2013-01-07: 9, ... } So, I did it like this which kind of works...: def self.total_grouped_by_day(start_date, end_date) visits = where(visited_at: start_date..end_date) visits = visits.group("date(visited_at)") visits = visits.select("date(visited_at) as date, count(visits.id) as total_visits") visits = visits.order("date ASC") visits.group_by...