How to add custom row to SQL dataset?

Hi there,

I have an SQL query that gived me a dataset as shown below. I want to add new column to this dataset, where the value in each row should be calulated based on values in the other coumns. How can I do this?

image

I want to subtract the value in red from the value in blue, and place the result in green. And repeat this for all rows.

The simplest solution would be to use your DB's LAG() function to do that math right in the SQL.

SELECT *, kwh - LAG(kwh) OVER (ORDER BY Timesamp) AS delta_kwh
FROM ....