Data cells

Hello, excuse my language but use a translator :smiley: , I ask you one help, I have tables that total the kwh, I need to extract the daily consumption directly from the ignition,
you think you can. :prayer:
Currently I take the values of two days, and I xy subtract the daily.
But the analysis should be done every three months
I attach a screen shot

Thank you very much

Hello, I explain, I have a table with values in kwh per day, every day I have to know the difference between consumption before and after and put the new value in the same table in another column and then extract all in csv,

Thank you very much

This is really a SQL problem. I would use a window aggregate function like so:SELECT t_stamp, "kWh", "kWh" - lag("kWh") OVER (ORDER BY t_stamp) AS "daily_kWh" FROM mytable WHERE t_stamp > ..... ORDER BY t_stampPostgreSQL documentation. Syntax varies a bit among the various DB platforms. MySQL and MariaDB can’t do this at all.

Hello , thank you for the swift response , I put the code in SQL syntax error , I feel the network administrator for this problem , I would like to know if this is fair that I put .
Thank you very much

The error message shows you are using MySQL. It doesn’t support window aggregate functions, as I stated.
You pasted my code sample verbatim. I made up column names. I didn’t provide a complete WHERE clause. You have to tailor the SQL to suit your application.
Also, please trim your screenshots. All that useless whitespace makes the whole topic really wide and hard to read. For error messages, it is better to switch the error message to “full”, copy the text, and paste it inside code /code tags.

Ok, sorry :prayer: , next time I paste only the error, I have to understand if they are on the right track

SELECT t_stamp,
“kwh_raw” - lag(“kwh_raw”) OVER (ORDER BY t_stamp) AS “kwh_giorno”
FROM Table 1
WHERE t_stamp >= ‘{Root}’ AND
t_stamp <= ‘{Root Container.Calendar.latchedDate}’
ORDER BY t_stamp

thank you

[quote=“Elettricman”]SELECT t_stamp, "kwh_raw", "kwh_raw" - lag("kwh_raw") OVER (ORDER BY t_stamp) AS "kwh_giorno" FROM Table 1 WHERE t_stamp >= '{Root}' AND t_stamp <= '{Root Container.Calendar.latchedDate}' ORDER BY t_stamp[/quote]This would work in PostgreSQL since v8.4, in MS SQL Server since 2012, and Oracle. (I don’t know how far back it is supported in Oracle, but certainly before 10g.)