【发布时间】:2015-04-02 18:53:38
【问题描述】:
当前查询完美,问题是当前月份(4 月)没有数据,因此它没有将月份列为 0,我如何让它将月份列为有 0 个干预?
查询
select distinct from_unixtime(interv_date,'%M %Y') AS month, count(*) as totals
from " . TABLE_PREFIX . "interviews
group by month
order by interv_date desc
limit 6
注意 interv_date 列是一个纪元时间戳(例如:1428003691)
PHP
<table class=\"highchart\" data-graph-container=\"#graphcontainer\" data-graph-type=\"column\" data-graph-legend-disabled=\"1\">
<caption>Interviews by Month</caption>
<thead>
<tr>
<th>Month</th>
<th>Totals</th>
</tr>
</thead>
<tbody>
<?php
for ($i = 0; $i < $stat_logs["count"]; $i++) {
echo "<tr>\n";
echo "<td>" . $stat_logs[$i]["month"] . "</td>\n";
echo "<td>" . $stat_logs[$i]["totals"] . "</td>\n";
echo "</tr>\n";
}
?>
echo "</tbody>
echo "</table>
输出
Month Totals
March 2015 7
February 2015 5
January 2015 12
December 2014 18
November 2014 19
October 2014 5
我需要它输出如下内容:
Month Totals
April 2015 0
March 2015 7
February 2015 5
January 2015 12
December 2014 18
November 2014 19
不要以为不是每个月都会有面试,所以不会只是当月(第一个月) 任何关于我如何让没有面试的月份出现在名单上的帮助都会很棒。
【问题讨论】:
-
您可能想要一个
month表,其中包含 Jan-Dec,然后在查询中加入。虽然如果当前的month列也包含年份,那可能会很混乱。 -
所以您对过去 6 个月的数据感兴趣,包括当前月份?
-
是包括当前月份,注意interv_date列是一个纪元时间戳