# Subqueries - nested continuous queries in InfluxDB

**URL:** <https://community.influxdata.com/t/subqueries-nested-continuous-queries-in-influxdb/15301>\
**Category:** Systems\
**Created:** [July 18, 2020, 7:46am UTC](https://community.influxdata.com/t/subqueries-nested-continuous-queries-in-influxdb/15301 "2020-07-18T07:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladpov](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@vladpov](https://community.influxdata.com/u/vladpov)\
**Post date:** [July 18, 2020, 7:46am UTC](https://community.influxdata.com/t/subqueries-nested-continuous-queries-in-influxdb/15301/1 "2020-07-18T07:46:20Z")

</div>

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 😃 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:

```
CREATE COUNTINOUS QUERY ON "db" 
BEGIN
SELECT mean(*) INTO "retentionPolicy".:MEASUREMENT FROM (SELECT * FROM "retentionPolicy" WHERE measurement != .:MEASUREMENT) GROUP BY time(1m),*
END

```

Is anything like this possible with InfluxDB subqueries?

Thanks for any support in this!

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [July 24, 2020, 7:02pm UTC](https://community.influxdata.com/t/subqueries-nested-continuous-queries-in-influxdb/15301/2 "2020-07-24T19:02:21Z")

</div>

Hello @vladpov,

I’m afraid this isn’t possible with InfluxQL because you can’t perform [math across measurements](https://www.influxdata.com/blog/influxdb-how-to-do-joins-math-across-measurements/).  
It is possible with [Flux](https://v2.docs.influxdata.com/v2.0/reference/flux/) and [Tasks](https://v2.docs.influxdata.com/v2.0/process-data/) however.  
You can use [joins](https://v2.docs.influxdata.com/v2.0/query-data/flux/join/) to compare values of one Task (which could replace your original CQ) or CQ with your original data.
