1

I'm trying to obtain a rolling average by user. I don't know if is possible but I've being trying for two days already with any luck. Hopefully somebody can help me :)

I want to obtain something like this:

Result expected

This is my query:

SELECT Date, User, QtyClosedTickets,
AVG(QtyClosedTickets) OVER (PARTITION BY User ORDER BY Date ASC rows between unbounded preceding and current row) AS RollingAvg
FROM Service

What I get is the average by each row instead the sum for previous rows, hope that makes sense.

  • That doesn't look like a rolling average, it looks like a cumulative sum. If it were an Average, your second row wouldn't have the value `8`, it would have the value 4 (as the average of `2` and `6` is `(2 + 6) / 2 = 4`). – Thom A Jan 25 '22 at 09:15
  • Just replace AVG by SUM, and change the alias to RollingSum – LukStorms Jan 25 '22 at 09:20

0 Answers0