# Divide 2 queries results in InfluxDB

**URL:** <https://community.influxdata.com/t/divide-2-queries-results-in-influxdb/10868>\
**Category:** Telegraf\
**Created:** [August 13, 2019, 7:32am UTC](https://community.influxdata.com/t/divide-2-queries-results-in-influxdb/10868 "2019-08-13T07:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien\_Cappiello](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/julien_cappiello/32/2953_2.png) [@Julien\_Cappiello](https://community.influxdata.com/u/Julien_Cappiello)\
**Post date:** [August 13, 2019, 7:32am UTC](https://community.influxdata.com/t/divide-2-queries-results-in-influxdb/10868/1 "2019-08-13T07:32:12Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![carpeliam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/carpeliam/32/5752_2.png) [@carpeliam](https://community.influxdata.com/u/carpeliam)\
**Post date:** [October 15, 2020, 3:33pm UTC](https://community.influxdata.com/t/divide-2-queries-results-in-influxdb/10868/2 "2020-10-15T15:33:33Z")

</div>

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](https://docs.influxdata.com/influxdb/v1.8/concepts/key_concepts/#sample-data), 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?

---

<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:** [October 16, 2020, 7:55pm UTC](https://community.influxdata.com/t/divide-2-queries-results-in-influxdb/10868/3 "2020-10-16T19:55:12Z")

</div>

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/](https://docs.influxdata.com/influxdb/v1.7/guides/calculating_percentages/)  
I’ll ask around. Thanks for your patience!
