Not sure how to explain this properly but here goes.
I a table with rows that are related to each other and I want to aggregate them based on a sort order until the value in one column has a certain value that would reset the group.
Sample table:
|cust_id|price |timestamp |type|
|-------|-------|------- |----|
|1 |10 |2021-01-29 12:32|1 |
|1 |20 |2021-01-29 12:33|2 |
|1 |15 |2021-01-29 12:34|2 |
|2 |10 |2021-01-29 12:33|1 |
|1 |20 |2021-01-29 12:34|1 |
|2 |10 |2021-01-29 12:35|2 |
Wanted result:
|cust_id|price |timestamp |type|
|-------|-------|------- |----|
|1 |45 |2021-01-29 12:32|1 |
|2 |20 |2021-01-29 12:33|1 |
|1 |20 |2021-01-29 12:34|1 |
So the input table would be sorted by timestamp and then grouped by cust id, the price is aggregated until the next occurrence where type is 1 which would indicate a new group. Type here is just one and two, but can in reality have a lot of different values.
I have not figured out a good way of accomplishing this so any pointers is appreciated.