title: SQL cumulative average by distinct column value (timestamp)
body: <p>I have a SQL table in the following form:</p>
  <p>timestamp user_id Result <br/>
  1         125  1<br/>
  1         125  0<br/>
  2         125  1<br/>
  2         144  0<br/>
  3         156  1<br/>
  3         125  1<br/></p>
  <p>etc....</p>
  <p>If I want to find a rolling average of a users results I can use:</p>
  <pre><code>SELECT user_id, timestamp, 
  AVG(result) OVER (PARTITION BY user_id ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) 
  FROM table
  </code></pre>
  <p>If a user only had one result per timestamp, this works fine but if a user have a multiple results in a single timestamp it will average over the results on that timestamp plus timestamps before it.</p>
  <p>So my question is how can I make sure it only averages over results which happened on when the timestamp is less than the current timestamp?</p>
  <p>Thanks in advance</p>