我一直在寻找关于 SO 的答案,但我没有解决我的问题。我有两张桌子,profiles
存储profiles_visitors
第一张的访客。
我想知道用户在过去 15 天内有多少访问者,所以我写了这个:
SELECT COUNT(pv.id) AS `count`, DATE(FROM_UNIXTIME(pv.created_at)) AS `date`
FROM profiles p
LEFT JOIN profiles_visitors pv ON pv.profiles_id=p.id
WHERE p.users_id='50' AND pv.created_at >= (CURDATE() - INTERVAL 15 day)
GROUP BY DATE(FROM_UNIXTIME(pv.created_at))
查询结果:
+-------+-------------------+
| count | date |
+-------+-------------------+
| 2 | 2012-10-26 |
+-------+-------------------+
| 3 | 2012-10-29 |
+-------+-------------------+
期望的结果:
+-------+-------------------+
| count | date |
+-------+-------------------+
| 0 | 2012-10-15 |
+-------+-------------------+
.......... 0s here ..........
+-------+-------------------+
| 0 | 2012-10-25 |
+-------+-------------------+
| 2 | 2012-10-26 |
+-------+-------------------+
| 0 | 2012-10-27 |
+-------+-------------------+
| 0 | 2012-10-28 |
+-------+-------------------+
| 3 | 2012-10-29 |
+-------+-------------------+
| 0 | 2012-10-30 |
+-------+-------------------+
先感谢您。