How to have a subquery from few queries in Influx?
Published in
1 min readFeb 18, 2019
If you have (f.e.) two queries, you may want to join them and to make a query on top of joined result of both previous queries. How to join them?
Query1:
select mean(value) as mean_rd from foo where type_instance='rd'
Query2:
select mean(value) as mean_wr from foo where type_instance='wr'
Query 3:
Select mean_wr + mean_rw from (previous two)
Answer
Select max(mean_wr) + max(mean_rw) from \
(select mean(value) as mean_rd from foo where type_instance='rd'),
select mean(value) as mean_wr from foo where type_instance='wr'
Put each request in brackets and join them by coma. Use ‘max’ for each value, as influx have trouble to operate on joined results without some kind of aggregate.