简体   繁体   English

获取从定义的月份到当月的每个月的数据

[英]Get data for each month from defined month up to current month

I need to provide monthly reports of bandwidth used from our mysql database since a particular month and year eg November, 2009. I can output the correct data for any particular month using the following query; 我需要提供自特定月份和年份(例如2009年11月)以来我们的mysql数据库使用的带宽的月度报告。我可以使用以下查询输出任何特定月份的正确数据;

$query='SELECT SUM(radacct.AcctInputOctets) AS uploads,SUM(radacct.AcctOutputOctets) AS downloads FROM radacct WHERE radacct.AcctStartTime BETWEEN "2010-11-00" AND "2010-12-00"';
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    echo '<tr><td>December</td><td>'.$uploads.'</td><td>'.$downloads.'</td></tr>';

I need to put this into a loop which starts from a defined month ie $start='2009-11-00' and prints out a record for each month up to and including the current month. 我需要将它放入一个从定义的月份开始的循环,即$ start ='2009-11-00',并打印出每个月的记录,包括当前月份。 Regardless of what I try, I cant get it to work! 无论我尝试什么,我都无法让它发挥作用!

Add a grouping parameter: 添加分组参数:

SELECT year(radacct.AcctStartTime), month(radacct.AcctStartTime), ...
FROM ...
WHERE radacct.AcctStartTime > '2010-09-00'
GROUP BY year(radacct.AcctStartTime), month(radacct.AcctStartTime)

Which would give you summary data for every year/month that has at least one entry in the database, since Sep. 2010. 这将为您提供自2010年9月以来在数据库中至少有一个条目的每年/每月的摘要数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM