我正在尝试收集有关我正在使用的数据库的统计信息,我想知道每月在数据库中创建了多少条目,因为时间范围超过一年而被卡住,例如它始于2010年2月,目前结束。
现在我正在尝试做这样的事情:
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);"`
...等 任何帮助/想法都会很棒。 感谢。
答案 0 :(得分:2)
添加GROUP BY MONTH(提交时间)。
答案 1 :(得分:1)
如下:
SELECT COUNT(id), CONCAT(MONTH(submittime),'-',YEAR(submittime)) AS start
FROM builds GROUP BY start
或者更简单地说
SELECT COUNT(id), submittime
FROM builds GROUP BY YEAR(submittime), MONTH(submittime)