即使没有结果,Mysql每天也显示 [英] Mysql show everyday between even if there are no results

查看:47
本文介绍了即使没有结果,Mysql每天也显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询

SELECT SUM(value1 +value2) AS total  ,created_at
FROM mytable
WHERE created_at 
BETWEEN '2013-10-1' AND '2013-10-19' 
GROUP BY created_at

返回

## total | created_at ##
  2500   | 2013-10-01
  6546   |  2013-10-05

但是我想要

## total | created_at ##
   2500  |  2013-10-01
   0     |   2013-10-02
   0     |   2013-10-03
   0     |   2013-10-04
   6546  |   2013-10-05

对于没有总和的日期,我想返回 0,以便表格每天显示范围之间任何帮助将不胜感激

I'd like to return 0 for dates with no sums so the table shows everyday between the range Any help would be appreciated

推荐答案

你可以像这里描述的那样做:

You could do it like it's described here:

获取两个日期之间的日期列表

但这意味着要创建一个额外的表.无论如何,我认为最好在代码级别进行...为什么不这样做?

But that would mean to create an extra table. Anyway, i think it's better that you do it at code level... why don't you do it that way?

这篇关于即使没有结果,Mysql每天也显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆