1
当前查询工作完美的问题是当前月份(4月)没有数据,因此它不会将月份列为0,我如何获取它以列出月份有0个interivews?列出当月没有来自数据库的数据
QUERY
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>
OUTPUT
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
拿不出,并不是每个月都会有面试,所以它不会只是当前月份(第一个月) 我如何能拿到个月,没有采访任何人的帮助出现在名单上会很棒。
您可能想要一个具有Jan-Dec的'month'表,然后在查询中加入JOIN。尽管如果当前的“月份”列也包含年份,那可能会很麻烦。 – AbraCadaver 2015-04-02 18:55:20
所以你有兴趣过去6个月的数据包括当前月份? – 2015-04-02 19:04:20
是包括当前月份,请注意interv_date列是纪元时间戳 – Manvaril 2015-04-02 19:39:23