79195696

Date: 2024-11-16 17:25:35
Score: 0.5
Natty:
Report link

Based on your explanation it seems like you don't need: RANGE BETWEEN INTERVAL '60' SECOND PRECEDING AND CURRENT ROW Or am I missing a requirement here?

If you eliminate this in your query, it will compute the running total per row it sees, despite the duplicates.

SELECT timestamp, SUM(volume) OVER (
        PARTITION BY ID
        ORDER BY timestamp
    ) AS total_volume
FROM YourTable;

The results:

timestamp               total_volume
2024-11-16 08:00:00.00  10
2024-11-16 08:00:00.00  20
2024-11-16 08:01:00.00  30
2024-11-16 08:02:00.00  40
2024-11-16 08:02:00.00  50
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Rafael Llopis