# Adding multiple fields matching a regular expression

**URL:** <https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496>\
**Category:** InfluxDB 1\
**Created:** [September 10, 2022, 2:34pm UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496 "2022-09-10T14:34:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://community.influxdata.com/u/franck102)\
**Post date:** [September 10, 2022, 2:34pm UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/1 "2022-09-10T14:34:33Z")

</div>

Hi all, using InfluxQL v1 I am trying to sum field values from multiple fields, over a given time range. I am trying this query:

```auto
SELECT sum(/^cumulus|rad|sdb$/) as Infra
  FROM iota_06.rt_energy.energy WHERE time >= now() - 24h and time <= now() fill(0)

```

… but this yields 3 columns (Infra\_cumulus, Infra\_rad, Infra\_sdb) - I would simply like them those 3 columns summed up… any suggestion?

I sent through the manual & the examples I could find but I can’t figure out how to write the query.

Thanks!

---

<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:** [September 13, 2022, 11:05pm UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/2 "2022-09-13T23:05:13Z")

</div>

Hello @franck102,  
It’s good to see you back!

hmm its been so long since I’ve used InfluxQL lol. Most of our users use 2.x and Flux now.  
are Infra\_cumulus, Infra\_rad, Infra\_sdb all fields?  
I think it would look like:

```auto
SELECT sum_1 + sum_2
    (SELECT SUM("field1") AS sum_1, SUM("field2") AS sum_2 FROM iota_06.rt_energy.energy WHERE time >= now() - 24h and time <= now() fill(0))

```

But I’m not 100% sure…(yikes it’s been a while) Can you please give it a try and let me know?

Alternatively if you’re using 1.x, then you can try the following flux query (just fyi).

```auto
from(bucket: "energy ")
  |> range(start:-24h)
  |> filter(fn: (r) => r["_measurement"] == " iota_06.rt_energy")
  |> filter(fn: (r) => r["_field"] == "field1" or r["_field"] == "field2")
  |> group()
  |> sum() 

```

---

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://community.influxdata.com/u/franck102)\
**Post date:** [October 14, 2022, 6:29am UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/3 "2022-10-14T06:29:45Z")

</div>

Sorry I missed your reply, I just tried your subquery today and it does work like a charm… thanks a lot!

Franck

---

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://community.influxdata.com/u/franck102)\
**Post date:** [October 14, 2022, 6:31am UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/4 "2022-10-14T06:31:38Z")

</div>

Regarding InfluxDB 2 btw, I have an old device that would require flashing to support writing to influx 2, and I haven’t found the time/motivation to get into it…

---

<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 17, 2022, 4:53pm UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/5 "2022-10-17T16:53:19Z")

</div>

@franck102 yay! I’m happy it worked for you.

What are you doing with InfluxDB? It really makes my day to learn about usecases rather than helping people without the satisfaction of the context. But…if that’s not enough motivation, you can also get a free hoodie:

> **[Get a hoodie](https://www.influxdata.com/get-hoodie/)**
>
> Share with us how you use InfluxDB in your products or business. We'd love to feature you on our site and send you an InfluxData hoodie.

---

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://community.influxdata.com/u/franck102)\
**Post date:** [October 17, 2022, 5:46pm UTC](https://community.influxdata.com/t/adding-multiple-fields-matching-a-regular-expression/26496/6 "2022-10-17T17:46:26Z")

</div>

I am tracking electrical PV production and usage using an Iotawatt device ([https://iotawatt.com/](https://iotawatt.com/); and data from an Okofen pellet heater.

Works like a charm, although fitting on the 1Gb RAM of my raspberry pi requires some retention policy tuning…
