获取两个日期之间的开始日期和结束日期

时间:2017-04-04 03:49:18

标签: mysql date

Get All Sunday and Lastday between two date

当我在查询中使用子查询时,我的问题是我的总和与真实不同。好吧,让我来看看实际数据

Day | Total
3/5/2017  | 22
3/12/2017 | 16
3/19/2017 | Null
3/26/2017 | 8

然后我使用子查询来实际数据变为

Date | Total
2017-03-05 | 22
2017-03-12 | 16
2017-03-19 | Null
2017-03-26 | 8
2017-03-31 | 8

我的查询

SELECT calender, (SELECT SUM(tblaa.Hours) FROM tblaa WHERE tblaa.Date >= '2017-03-01' and tblaa.Date <= '2017-03-31' and tblaa.class = "INDIR" and tblaa.action = '0' AND WEEK(tblaa.Date) = WEEK(calender.calender)) AS Hours FROM calender WHERE calender.calender >='2017-03-01' AND calender.calender <='2017-03-31' AND DAYOFWEEK(calender) = 1 OR calender = '2017-03-31' Group By calender

我需要输出成为:

first | last | total
2017-03-01 | 2017-03-05 | 22
2017-03-06 | 2017-03-12 | 16
2017-03-13 | 2017-03-19 | Null
2017-03-20 | 2017-03-26 | Null
2017-03-27 | 2017-03-31 | 8

这个结果我按周(calender.calender)分组然后在2017-03-26总共8 但是当我分组按日历时,然后2017-03-31日没有取出。 请告诉我,谢谢

0 个答案:

没有答案