l'arbre
l'arbre

Reputation: 719

MySQL sum values from same day

I have a table which looks like this:

visitor_count INT UNSIGNED NOT NULL DEFAULT 0,
log_time DATETIME

As you can tell, it logs how many visitors there where in certain time periods. Now I want to show these values in a graph. I need to be able to "zoom out" meaning that I want to sum up all the visitor_counts whos log_time belongs to the same day, week, month. Is anything like this possible in SQL/MySQL with the aid of PHP (I'd prefer doing it in SQL since I believe it is much more efficient than getting all the values and summing them up in PHP)?

Upvotes: 2

Views: 2043

Answers (1)

Mureinik
Mureinik

Reputation: 311188

You could extract just the date part and sum according to it:

SELECT   DATE(log_time), SUM(visitor_count)
FROM     mytable
GROUP BY DATE(log_time)

Upvotes: 5

Related Questions