Doing maths with collected data

My setup is some sensors and HA collecting it’s values, storing it with MariaDB and showing.

I want to compute mean/min/max/another values for each day/week/month/year and then plot it to explore or doing other things…

Because I’m newbie with HA I ask you to advice me how to do computation (math) things in HA? How to do selection from db (within HA) to do maths with? How to store it to plot?

I’m interested in studying this… So will be grateful if you’ll give me any articles/… with explanations.

Try these pages

As I found here, I can only build SQL “sensor” which will react only on NEW data.
But I want to analyze old data stored in db.

For example: I want to calculate mean (average) value for each day, store it in db and then plot it.