title: How to calculate average number of days between dates in date order
body: <p>Table contains order dates</p>
  
  <pre><code>create table orderdate ( orderdate date not null )
  </code></pre>
  
  <p>How to calculate average days between dates in table.
  Difference needs to be calculated between neighbour dates in date order to find average number of dates between orders. </p>
  
  <p>Adding this number to last order date produces estimated next order date.</p>
  
  <p>For example if table contains</p>
  
  <pre><code>2019-09-10
  2019-09-21
  2019-09-25
  </code></pre>
  
  <p>differences between orders are 10 and 4 days  and average difference is</p>
  
  <pre><code>(10+4)/2 = 7 days
  </code></pre>
  
  <p>next order esimated date is 2019-09-25 + 7 = 2019-10-02</p>
  
  <p>Using</p>
  
  <pre><code>PostgreSQL 9.4.19
  </code></pre>