Hello,
I have a measurement of integer data like this, there can be several lines with the same value, but sometimes also only one. Like this:
_measurement _time _field _value
test 2021-01-01T00:00:00Z state 1
test 2021-01-01T00:00:10Z state 1
test 2021-01-01T00:00:20Z state 2
test 2021-01-01T00:00:30Z state 3
test 2021-01-01T00:00:50Z state 1
test 2021-01-01T00:00:55Z state 2
Now I want to get a table which shows me which state is how long active an in which order they occure:
_measurement _time _field _value _duration
test 2021-01-01T00:00:00Z state 1 20
test 2021-01-01T00:00:20Z state 2 10
test 2021-01-01T00:00:30Z state 3 10
test 2021-01-01T00:00:50Z state 1 20
test 2021-01-01T00:00:55Z state 2 5
Thank You, this brought me quite close to the solution, but one thing is still wrong. My output example in my initial post has also one error. The duration is off by one row, this is how it should look like:
_measurement _time _field _value _duration
test 2021-01-01T00:00:00Z state 1 20
test 2021-01-01T00:00:20Z state 2 10
test 2021-01-01T00:00:30Z state 3 20
test 2021-01-01T00:00:50Z state 1 5
test 2021-01-01T00:00:55Z state 2
I now use this query, which has two problems:
The first two rows are missing
I am one off with the elapsed row state 3 lasts for 20s not 10s