title: Difference between two rows with date in ascending order
body: <p>I am trying to write a query which calculates the difference between the value rows as a new column called difference when the datetime field is in ascending order. </p>
  
  <p>For example, 2016-03-02 should be 102340624 - 102269208 </p>
  
  <pre><code>select datetime, tagname, value
  from runtime.dbo.AnalogHistory
  where datetime between '20160301 00:00' and '20160401 00:00'
  and TagName = 'EWS_A3_PQM.3P_REAL_U'
  and wwResolution = (1440 * 60000)
  order by DateTime asc
  
  DATETIME                    TAGNAME                 VALUE       DIFFERENCE
  2016-03-01 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102269208
  2016-03-02 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102340624
  2016-03-03 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102411568
  2016-03-04 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102478104
  2016-03-05 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102549088
  2016-03-06 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102612592
  2016-03-07 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102682984
  2016-03-08 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102747000
  2016-03-09 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102817176
  2016-03-10 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102887896
  </code></pre>
  
  <p>Thank you very much in advance</p>