在 some_table 中创建的每个“记录”都有一个“日期”。
一些表:
-------------------------
id | record | my_date
-------------------------
1 | rec_a | 2012-08-01
2 | rec_b | 2012-08-02
3 | rec_c | 2012-08-02
4 | rec_d | 2012-08-04
5 | rec_e | 2012-08-06
6 | rec_f | 2012-08-06
我的查询:
start_date 和 end_date 来自输入
SELECT
my_date, COUNT(my_date) AS _count
FROM
some_table
WHERE
my_date
BETWEEN
start_date
AND
end_date
GROUP BY
DAY (my_date)
大批:
while($result = mysql_fetch_assoc($my_query))
{
$dataset[] = array($result['my_date'],intval($result['_count']));
}
json_encode($dataset);
这将使:
["2012-08-01",1]
["2012-08-02",2]
["2012-08-04",4]
["2012-08-06",6]
获得没有这样计数的日子的最佳方法是什么?
["2012-08-01",1]
["2012-08-02",2]
["2012-08-03",0] <--
["2012-08-04",4]
["2012-08-05",0] <--
["2012-08-06",6]