June 24, 2011 at 8:36 am
Something like this?
;WITH id_CTE AS (
SELECT name, status, fordate, a,
ROW_NUMBER() OVER (ORDER BY fordate ASC) AS id
FROM #data),
work_CTE AS (
SELECT name, status, fordate, a, id
FROM id_CTE
WHERE id = 1
UNION ALL
SELECT a.name, a.status, a.fordate, (a.a+b.a+c.a)/3.0 AS a, a.id
FROM id_CTE a
INNER JOIN id_CTE b ON a.id-1 = b.id
INNER JOIN id_CTE c ON a.id-2 = c.id)
SELECT name, status, fordate, a AS average FROM work_CTE
June 24, 2011 at 9:01 am
@ skcadavre
That worked like a dream.
Thank you
:-):-)
taybre
HTH :-):-)
taybre
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 2 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply