我在我的表上运行以下查询:
SELECT DISTINCT(date(dateAdded)) AS dateAdded, count(*) AS count FROM clients WHERE (dateAdded BETWEEN '2012-06-15' AND '2012-06-30') GROUP BY dateAdded ORDER BY dateAdded ASC
这将返回如下内容:
2012-06-17 ¦ 5
2012-06-19 ¦ 2
2012-06-26 ¦ 3
2012-06-30 ¦ 2
我需要能够填写日期范围内的任何缺失日期,如下所示:
2012-06-15 ¦ 0
2012-06-16 ¦ 0
2012-06-17 ¦ 5 <--
2012-06-18 ¦ 0
2012-06-19 ¦ 2 <--
2012-06-20 ¦ 0
2012-06-21 ¦ 0
2012-06-22 ¦ 0
2012-06-23 ¦ 0
2012-06-24 ¦ 0
2012-06-25 ¦ 0
2012-06-26 ¦ 3 <--
2012-06-27 ¦ 0
2012-06-28 ¦ 0
2012-06-29 ¦ 0
2012-06-30 ¦ 2 <--
如果可能的话,我想使用某种 PHP 循环来做到这一点。任何帮助将不胜感激。