MySQL 棘手的日期时间查询
我有一个有效的日期时间查询 qreat:
$q="SELECT COUNT(blocked) AS sum_blocked, DATE(created) AS date_label ".
"FROM sms_subscribers WHERE blocked=0 GROUP BY DATE(created)";
唯一的问题是我无法弄清楚如何/是否可以用零或空来填充零结果的日期。
IE;如果 2011-08-25 有 5 条记录,2011-08-27 有 7 条记录,我希望结果返回 5, 0, 7 或 5, null, 7
任何帮助将不胜感激!
I have a datetime query that works qreat:
$q="SELECT COUNT(blocked) AS sum_blocked, DATE(created) AS date_label ".
"FROM sms_subscribers WHERE blocked=0 GROUP BY DATE(created)";
The only problem is I can not figure out how / if I can fill dates with zero results with zero or null.
ie; if there are 5 records for 2011-08-25 and 7 records for 2011-08-27, I would like the result to return 5, 0, 7 or 5, null, 7
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个包含天数的附加表并连接两个表。这是一个示例,它适用于指定月份 -
You could create an additional table with number of days and join two tables. Here it is an example, it works for specified month -