Skip to content

Instantly share code, notes, and snippets.

@johnmcaliley
Created August 17, 2012 13:14
Show Gist options
  • Save johnmcaliley/3378639 to your computer and use it in GitHub Desktop.
Save johnmcaliley/3378639 to your computer and use it in GitHub Desktop.
article.impressions.create
article.impressions.create(:created_at => "2000-01-01")
article.impressions.create(:created_at => "2000-01-01")
article.impressions.create(:created_at => "2000-01-02")
impressions = article.impressions.select("count(*) as count, DATE_FORMAT(created_at,'%Y-%m-%d') as created_day").group("created_day")
impressions.each do |impression|
p "#{impression.created_day}: #{impression.count}"
end
@johnmcaliley
Copy link
Author

This should output:

"2000-01-01: 2"
"2000-01-02: 1"
"2012-08-17: 1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment