1

Get All Sunday and Lastday between two date

I've problem that my sum is different with the real when i use subquery in the query. Ok let's me show the actual data

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

And then i use subquery to the actual data become

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

My Query

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

I need the output become :

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

This result i group by week(calender.calender) then at 2017-03-26 has total 8 But when i Group By calender.calender then Day 2017-03-31 not fetch out. Please show me the way, Thanks

Community
  • 1
  • 1
Mas Harjo
  • 73
  • 9

0 Answers0