Archiving old data in new table scheduled task

Hello everyone! I have an installation of influxdb and grafana on a hassio server (home assistant). Through queries, I create histograms of energy consumption with the data of the whole day. The query is very heavy. I would therefore like to create a new table with the data already processed in order to be quick in consulting the history. I am not interested in going into the details of consumption for the past few days. How can I execute tasks at midnight that take the result of a query from the previous day and create only one piece of data? I hope I explained myself. I use InfluxQL

i believe this is more of influx question than a grafana question. but that said, you can leverage the following

or maybe use python to automate this for you? If you look at https://community.influxdata.com/