Discrete Derivative in SQL Discrete Derivative in SQL sql sql

Discrete Derivative in SQL


Select a.Time as StartTime, b.time as EndTime, b.time-a.time as TimeChange, b.value-a.value as ValueChangeFROM YourTable a, YourTable bWHERE b.time = (Select MIN(c.time) FROM YourTable c WHERE c.time>a.time)


Select a.Time as StartTime     , b.time as EndTime     , b.time-a.time as TimeChange     , b.value-a.value as ValueChangeFROM YourTable a Left outer Join YourTable b ON b.time>a.timeLeft outer Join YourTable c ON c.time<b.time AND c.time > a.timeWhere c.time is nullOrder By a.time


you could use a SQL window function, below is an example based on BIGQUERY syntax.

SELECT   LAG(time, 1) OVER (BY time) AS start_time,  time AS end_time,   (value - LAG(value, 1) OVER (BY time))/value AS Changefrom data