• I would probably use AVG and the OVER clause in TSQL to work this one out.

    http://technet.microsoft.com/en-us/library/ms189461.aspx

    Look at the examples under "Using the OVER clause with aggregate functions"