Created
December 2, 2011 02:06
-
-
Save typeoneerror/1421392 to your computer and use it in GitHub Desktop.
count of results per day of last week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
EXTRACT(DAY FROM created_at) AS the_day, | |
COUNT(created_at) AS count_all | |
FROM "results" | |
WHERE "results"."result_type" = 'outcome' | |
AND (DATE("results"."created_at") BETWEEN '2011-11-21' AND '2011-12-01') | |
GROUP BY created_at | |
ORDER BY created_at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :recent, lambda { | |
select(['EXTRACT(DAY FROM created_at) AS the_day', 'COUNT(created_at) AS count_all']) | |
.where("DATE(created_at) BETWEEN ? AND ? ", Date.today.prev_week, Date.today) | |
.group(:created_at) | |
.order(:created_at) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment