Sample Header Ad - 728x90

Make sequential groups of rows that surpass a minimum sum

1 vote
1 answer
40 views
Let's say I have a table with a timestamp (ts) and a value (a). With some sample data:
ts, a
1, 10
2, 30
3, 10
4, 20
5, 40
6, 10
7, 20
8, 30
etc
I would like to group rows, in ts order, by summing a and outputting a row where the sum of a is > 50. In this case, the output should be two timestamps (first and last row):
1, 3  -- 10 + 30 + 10
4, 5  -- 20 + 40
6, 8  -- 10 + 20 + 30
But I have no clue how to proceed. All attempts I did with Copilot yield complex code that never finishes.
Asked by Thomas (355 rep)
Aug 12, 2024, 04:14 PM
Last activity: Aug 14, 2024, 01:09 AM