I am trying to gather statistics about a database that I am working with, I want to know how many entries were made in the database per month, I'm stuck because the timeframe is longer than one year, e.g. it start开发者_如何学运维s in Feb 2010 and ends at the present.
Right now I am trying to do something like this:
startDate = `mysql -h <hostname> -u root -D build -e "select MIN(submittime) '
Start Date' from builds;"`
endDate = `mysql -h <hostname> -u root -D build -e "select MAX(submittime) 'En
d Date' from builds;"`
months = []
months.push(`mysql -h <hostname> -u root -D build -e "select count(id)
from builds where submittime >= startDate
and submittime <= date_add(startDate, interval 30 DAY);"`
etc... Any help/ideas would be great. Thanks.
add GROUP BY MONTH(submittime).
How about something like:
SELECT COUNT(id), CONCAT(MONTH(submittime),'-',YEAR(submittime)) AS start
FROM builds GROUP BY start
or, more simply
SELECT COUNT(id), submittime
FROM builds GROUP BY YEAR(submittime), MONTH(submittime)
精彩评论