Divide 2 queries results in InfluxDB

I have 2 queries:

select sum(redistributed) from measures where meter_id='3P00XX' AND  $timeFilter group by time(30m)

which get sum of redistributed field for meter '3P00XX' on 30 minutes timestep.

And:

select sum(redistributed) from measures where  operation_id='AC15' AND  $timeFilter group by time(30m)

Which do the same thing, but for the whole operation ( a operation has a lot of meters ). It can be considered as total field.

So, what I want to do is a ratio, sum_of_redistributed / total, for the meter_id for each 30 minutes.

Right now, I’m doing it in n+2 queries:

  • n + 1, if n is the quantity of meters,
  • 1 for the total.

And then I calculate the ratio in go, but it would be quite an improvement to get the ratio directly from a query. Is it possible ?

Is it possible to improve the query ?

Coming in just to say “I have the same question” - I want to calculate a ratio of the number of points in a series to the number of points in a larger series for the same measurement - so if I had a census measurement as described in InfluxDB key concepts | InfluxDB OSS 1.8 Documentation, I might want to know “what percentage of points have “langstroth” as the scientist, within the last week.” I’m using Grafana to graph this ratio, and so @Julien_Cappiello’s strategy of using Go is unavailable to us. Is this unsolvable using InfluxDB 1.8 with InfluxQL? Is there a way to structure our data that makes this possible?

Hello @carpeliam,
You would probably use a subquery. I’m not sure how to do that with tags though. https://docs.influxdata.com/influxdb/v1.7/guides/calculating_percentages/
I’ll ask around. Thanks for your patience!