I used the LAG() window function to subtract the the previous row’s value:
SELECT DateTimeStamp, DMS1, DMS1 - LAG(DMS1) OVER (ORDER BY DateTimeStamp) AS HourlyDMS1 FROM vPLANTDATA ORDER DateTimeStamp;
The documentation for LAG() is found here : https://learn.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver17
I tried the following query and got this op: