T-SQL calculate moving average
问题 I am working with SQL Server 2008 R2, trying to calculate a moving average. For each record in my view, I would like to collect the values of the 250 previous records, and then calculate the average for this selection. My view columns are as follows: TransactionID | TimeStamp | Value | MovAvg ---------------------------------------------------- 1 | 01.09.2014 10:00:12 | 5 | 2 | 01.09.2014 10:05:34 | 3 | ... 300 | 03.09.2014 09:00:23 | 4 | TransactionID is unique. For each TransactionID , I