Tuesday, 13 August 2013

How to phrase MySQL query to get daily totals for a column in groups?

How to phrase MySQL query to get daily totals for a column in groups?

Ok, so I have the following table structure:
vote_id date user source
-------- ------ ------ --------
1 2013-07-23 01:37:25 user1 x
2 2013-07-23 13:15:10 user2 y
3 2013-07-23 22:30:53 user3 x
4 2013-07-24 17:38:46 user1 y
What I want to get in a query is the number of votes per day for each
source. The issue is that I record the date to the second, but I want it
sorted by day in the query.
e.g. The result would be something like this:
2013-07-23 source: x votes: 10
2013-07-23 source: y votes: 2
2013-07-24 source: x votes: 0
2013-07-24 source: y votes: 6
So for every day there will be the total number of votes per source (the
number of sources isn't specified, it can be anything).
Any ideas? This query is a bit above me atm.

No comments:

Post a Comment