I am trying to write the equivalent LINQ for this rolling average SQL statement but I am struggling with how to use the same table (BulbSales) twice aliased as x and y.
Can you help?
SELECT x.Id, AVG(y.Sales) moving_average
FROM BulbSales x, BulbSales y
WHERE x.Id>=6 AND x.Id BETWEEN y.Id AND y.Id+5
GROUP BY x.Id
ORDER BY x.Id
If this is LINQ to SQL, you can try:
This produces the SQL: