Calculate and store result


I might ask for some newbies question beause i’m quite new to influxDB but trying to understand few thing.

I made a TIG stack which i use for a specific project, some kind of counter.
I got some devices sending to telegraf counter data (number between -10 to 20) every 5 sec or so, which is stored in InfluxDB.
I use Grafana to vizualize these data which consist of a graph over time with the sum of all these tick data for 24 hours.

It works fine but i don’t think it’s very efficient because the grafana vizualisation use a query that will sum all these data.

example : SELECT cumulative_sum(sum(“counterdata”)) FROM measurement.field WHERE bla bla bla AND time >= now() - 24h GROUP BY time($__interval)
So if i’m right every time the visualization refresh it will look at all data and do a calulation again (sum) of these and graf over time.

What i would like is create another table which contain already calculated data like 1 record ever 5 or 10 sec so there is not need to calculate anything when querying for vizualisation.
How influxDB can query, calculate and store every xxx sec automaticaly ?

I checked how to do that and wondering if continous queries or anything else would be more appropriated to do that (Flux maybe)

What do you think ?

Sorry for my bad english.