I have a table with time series. It contains `snapshot` and `increment` value

- `snapshot` means concrete value
- `increment` means take previous snapshot and add increment value to get snapshot value
```
sensor_id - id of sensor
ts - timestamp
temp - temperature at a given ts
value_type - 0 means snapshot, 1 means increment

sensor_id | ts | temp | value_type
sensor_X | 1 | 100 | 0
sensor_X | 2 | 5 | 1
sensor_X | 3 | -2 | 1
sensor_X | 4 | 95 | 0

sensor_Y | 4 | 90 | 0
sensor_Y | 5 | -5 | 1
```

My goal is to build time series view from table
```
 1| 2| 3| 4| 5| 
sensor_X 100| 105| 103| 95| | 
sensor_Y | | | 90| 85| 
```

user queries data by ts range and sensor_id:
```
show me sensor temperature where sensor_id starts with sensor_0* and ts in range (2023-01-20, 2023-01-23)
```

I can't come up with an idea how to calculate snapshot values.