mysql-求一个Mysql语句 查询出当前周的数据按照天分组

  • A+
所属分类:mysql教程
摘要

SELECT DATE_FORMAT(uploadTime_beg, “%Y-%m-%d”) as time, SUM(field01) as sumStatus1, SUM(field02) as sumStatus2, SUM(field03) as sumStatus3, SUM(field04) as sumStatus4, SUM(field05) as sumStatus5 FROM health_realdata WHERE DATE_FORMAT(upload

mysql数据数据库

SELECT
DATE_FORMAT(uploadTime_beg, "%Y-%m-%d") as time,
SUM(field01) as sumStatus1,
SUM(field02) as sumStatus2,
SUM(field03) as sumStatus3,
SUM(field04) as sumStatus4,
SUM(field05) as sumStatus5
FROM
health_realdata
WHERE DATE_FORMAT(uploadTime_beg,'%Y%u') = DATE_FORMAT(CURDATE(),'%Y%u')
GROUP BY DATE_FORMAT(uploadTime_beg,"%Y-%m-%d");

    这个SQL查出的数据如下:    ![图片说明](http://img.ask.csdn.net/upload/201511/24/1448359276_377950.png)    我想要的效果是:虽然数据库中没有2015-11-25的数据,但是也要查出来,只是后面的值显示为0.    请问在MYSQL中如何实现,上面的SQL如何修改呢。    我看到网上说需要一个日历辅助表,说的不是很详细,我试了一下好像有问题,如果这种方法可行,还请大牛们写详细点,谢谢。

除非注明,否则均为@蒲公英网原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.aipgy.com/409652.html

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: