Intenta el siguiente codigo:
Código SQL:
Ver originalIF Object_ID('tempdb..#PC','U') IS NOT NULL DROP TABLE #PC;
GO
CREATE TABLE #PC(code INT,
model INT,
price DECIMAL(10,2));
GO
INSERT
INTO #PC(code,model,price)
SELECT 1,1232,600 UNION ALL
SELECT 2,1121,850 UNION ALL
SELECT 3,1233,600 UNION ALL
SELECT 4,1121,850 UNION ALL
SELECT 5,1121,850 UNION ALL
SELECT 6,1233,950 UNION ALL
SELECT 7,1232,400 UNION ALL
SELECT 8,1232,350 UNION ALL
SELECT 9,1232,350 UNION ALL
SELECT 10,1260,350 UNION ALL
SELECT 11,1233,980 UNION ALL
SELECT 12,1233,970;
SELECT *,
(SELECT Avg(price) FROM #PC T2 WHERE T1.code-T2.code BETWEEN 0 AND 5) Promedio
FROM #PC T1
ORDER BY code;
El resultado que yo obtengo:
Código:
code model price Promedio
1 1232 600.00 600.000000
2 1121 850.00 725.000000
3 1233 600.00 683.333333
4 1121 850.00 725.000000
5 1121 850.00 750.000000
6 1233 950.00 783.333333
7 1232 400.00 750.000000
8 1232 350.00 666.666666
9 1232 350.00 625.000000
10 1260 350.00 541.666666
11 1233 980.00 563.333333
12 1233 970.00 566.666666
En filas 6 & 7 el promedio es 783.3333 y 750,
exactamente como en el ejemplo en tu pregunta.