samedi 3 janvier 2015

Get a count of records created each week in SQL

I have a table Questions. How can I get a count of all questions asked in a week?


More generically, how can I bucket records by the week they were created in?



Questions
id created_at title
----------------------------------------------------
1 2014-12-31 09:43:42 "Add things"
2 2013-11-23 02:98:55 "How do I ruby?"
3 2015-01-15 15:11:19 "How do I python?"
...


I'm using SQLLite, but PG answers are fine too.


Or if you have the answer using Rails ActiveRecord, that is amazing, but not required.


I've been trying to use DATEPART() but haven't come up with anything successful yet: http://ift.tt/KE9GuS


Aucun commentaire:

Enregistrer un commentaire