Subqueries - nested continuous queries in InfluxDB

Hey everyone!

I’m trying to write a query that would execute mean function on result of another query, which would return all measurements in database that are not part of certain retention policy.

The reason why I’m trying to do this is that I have couple of independent queries that are running on different measurements with mean function to avoid naming new mean fields with the “mean_value” if you get me :smiley: So above it I need some continuous query that would run on new measurements that would be created and for which I wouldn’t have gotten any particular query yet.

So something that could look like:

SELECT mean(*) INTO "retentionPolicy".:MEASUREMENT FROM (SELECT * FROM "retentionPolicy" WHERE measurement != .:MEASUREMENT) GROUP BY time(1m),*

Is anything like this possible with InfluxDB subqueries?

Thanks for any support in this!

Hello @vladpov,

I’m afraid this isn’t possible with InfluxQL because you can’t perform math across measurements.
It is possible with Flux and Tasks however.
You can use joins to compare values of one Task (which could replace your original CQ) or CQ with your original data.