title: Getting Average Time between list of successive dates in TSQL
body: <p>I have a table of events, each row has a StartDateTime column. I need to query a subset of events(say by userID) and determine the average number of days between successive events.</p>
  
  <p>The table basically, looks like this.</p>
  
  <pre><code>TransactionID   TransactionStartDateTime
  ----------------------------------------
  277             2011-11-19 11:00:00.000
  278             2011-11-19 11:00:00.000
  279             2012-03-20 15:19:46.160
  288             2012-03-20 19:23:06.507
  289             2012-03-20 19:43:41.980
  291             2012-03-20 19:55:17.523
  </code></pre>
  
  <p>I have attempted to adapt the following query referenced in this <a href="https://stackoverflow.com/questions/1946916/query-to-calculate-average-time-between-successive-events">Question</a>:</p>
  
  <pre><code>select a.TransactionID, b.TransactionID, avg(b.TransactionStartDateTime-a.TransactionStartDateTime) from
       (select *, row_number() over (order by TransactionStartDateTime) rn from Transactions) a
  join (select *, row_number() over (order by TransactionStartDateTime) rn from Transactions) b on (a.rn=b.rn-1)
  group by
  a.TransactionID, b.TransactionID
  </code></pre>
  
  <p>But I am not having any luck here as the original query was not expecting DateTimes</p>
  
  <p><strong>My expected result is a single digit representing average days</strong>(which I now realize is not what the query above would give)</p>
  
  <p>Any ideas?</p>