Get all records inside time intervals given by another stream of tables

Hello there !

I’m new quite new in InfluxDB and I wanted to know how to do a query in flux.
In that query, let’s say there is some specifications :

  • The bucket is named ‘TestBucket
  • In this bucket, there is 2 measurements : ‘M1’ and ‘M2’.
  • I’m targetting a time range from ‘T1’ to ‘T2’ for both measurements.
  • Both measurements have records with integer values.

The goal to this query is to returns all the records of M1 during the same intervals where the average value of M2’s records are less than 50, for every 3s intervals.

I tried something like this but I only have the M1’s records that matches the end time of each M2’s interval…

import “join”

left =
from(bucket: “TestBucket”)
|> range(start: T1, stop : T2)
|> filter(fn: (r) => r[“_measurement”] == “M2”)
|> aggregateWindow(every: 3s, fn: mean, createEmpty: false)
|> filter(fn: (r) => r._value < 50)
|> group(columns: [“_time”])
//|> yield(name: “LEFT”)

right =
from(bucket: “TestBucket”)
|> range(start: T1, stop : T2)
|> filter(fn: (r) => r[“_measurement”] == “M1”)
|> group(columns: [“_time”])
//|> yield(name: “RIGHT”)

result = join.inner(
left: left,
right: right,
on: (l, r) => l._time == r._time,
as: (l, r) => ({r with}),
|> group()
|> yield(name: “RESULT”)

How could I resolve my goal ?

Tank you all for your answers :grinning: