SELECT NZDate - CAST(NZDate - '2005-01-01' AS int) % 7 AS WeekStarting, sum(score)/7
from myTable
where (NZDate between '2005-01-01' and '2005-01-21') and name IN ('John','Bob','Harry')
group by NZDate - CAST(NZDate - '2005-01-01' AS int) % 7
order by weekstarting
Hi, I have a query (above) that given any start date (2005-01-01) and end date (2005-01-21), returns a result set as such:
2005-01-01 56.4 (contains mean of all values between '2005-01-01' and '2005-01-07')
2005-01-08 64.8
2005-01-15 45.7
This works good, except now I have been asked to change this so it returns the mean for 79 years
i.e. in the example above also gets the values for the three 7 day periods from 1927 to 2005 and averages them
to return a result set that looks like this:
2005-01-01 45.8 (contains mean of all values between '****-01-01' and '****-01-07' for 1927 to 2005)
2005-01-08 56.4
2005-01-15 34.9
Please help me!
Thanks