What do i have to change in my query that i can calculate the time between these two timestamps?
Or is there a better way to achive this?
My query is the following
@Patseevents.duration() calculates the time between subsequent rows. You need to compare times in the same row. To do this correctly, you should use join() instead of union(), and then map() to calculate the difference between two column values:
tab1 = // ... your table1 query
|> last()
tab2 = // ... your table2 query
join(
tables: {t1: tab1, t2: tab2},
on: ["ID"]
)
|> map(fn: (r) => ({ r with
duration: int(v: r.time_t1) - int(v: r._time_t2)
}))
The _value column gets removed with pivot() and is replaced by the columnKey. toString() requires a _value column, but you can replicate the transformation with map() and string(). In fact, you can replace keep(), rename(), and toString() with a single map() call: