Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello - I am grouping the sum of page requests and the average page wait time of an application by week and year. My problem is that using 'group by datepart(wk, date)' creates a row for the partial weeks (made of < 7 days) at the beginning and end of the year, so the sum of page requests for those two weeks is artificially low. How can I add the values of two rows together to make the value of page requests complete for a whole week each new year? requests page wait year week98395 1.867142 2007 5192013 1.702857 2007 5213906 1.725000 2007 5361057 1.830000 2008 1131461 2.290000 2008 2115725 1.987142 2008 3My query so far:SELECT x.*FROM (SELECT TOP 90SUM(Requests) AS 'Weekly Page Requests', AVG([Average Wait]) AS 'Weekly Average of Daily Average Pagewait', Datepart(yy, date) as 'year', Datepart(wk, date) as 'week'FROM PageWaits_Warehouse_Daily as pw WITH (NOLOCK)GROUP BY Datepart(yy, date), Datepart(wk, date)ORDER BY 'year' desc, 'week' desc) as xORDER BY 'year' asc, 'week' asc
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2008-02-08 : 12:51:26
Does this work?
SELECT TOP 90 SUM(Requests) AS 'Weekly Page Requests', AVG([Average Wait]) AS 'Weekly Average of Daily Average Pagewait', Datepart(yy, min([date])) as 'year', Datepart(wk, min([date])) as 'week' FROM PageWaits_Warehouse_Daily as pw WITH (NOLOCK) group by datediff(day, 0, [date]) / 7 ORDER BY min([date]) desc