title: How to understand the results of rows between 2 preceding and current row?
body: <p>My SQL query is:</p>
  
  <pre><code>SELECT time, buy,
    avg(buy) OVER (ORDER BY time rows between 1 preceding and current row) as average_2,
    avg(buy) OVER (ORDER BY time rows between 2 preceding and current row) as average_3
  FROM my_table; 
  </code></pre>
  
  <p>I'm trying to understand these window functions. I used some test data and got results:</p>
  
  <pre><code>TIME                       BUY  AVERAGE_2  AVERAGE_3
  ------------------- ---------- ---------- ----------
  2019-05-05 10:05:19          1          1          1
  2019-05-05 10:05:22          2        1.5        1.5
  2019-05-05 10:05:25          3        2.5          2
  2019-05-05 10:05:27          4        3.5          3
  </code></pre>
  
  <p>I need to know: how do I get these results? Specially <code>average_3</code>?</p>
  
  <p>What is the difference between <code>ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW</code> and <code>rows between 2 preceding and current row</code>? I read many explanations from the internet, now I'm confused because they have explained with different syntax.</p>