[SOLVED] One off integral calculation for energy related data

I’d like to do a one off calculation of the energy my home battery system has provided in it’s lifetime.
I’ve got a sensor that tracks the battery discharge energy I know I can set a template sensor integrting it’s value let’s say over a 10 year period but If I’m not wrong this will start at 0 and increase over time, furthermore in this way I think HA will continuously update that sensor, a thing that I don’t need at all.

The objective is to find, at current enegy prices where I live (I have a flat tariff), the average return of investment on the battery pack and decide, when the state of health of the battery will be lower if/when replace the battery itself.

I use mariadb as my backend with 366 days of retention. Is there a way to craft a SQL query to do the calculations? Or, better still, is there a statistic already readable?

Nevermind, I discovered my inverter keep tracks of lifetime energy data, so I needed only to sum the discharged energy counter for the 2 battery packs to gather the info.

It would be interesting tough to see if there are other ways to find the info because there are cases in which I’d like to find some spot calculated value without having the need to store forever that information.