title: Sum Column as an Accumulation Based on a Time Period
body: <p>I have a table in which records are inserted at different periods (each record contains a column called 'Amount'). </p>
  
  <p>I want to show the total amount acummulation, after each 5 seconds. I have tried with the following query without success:</p>
  
  <pre><code>SELECT Sum(totalamount) AS RealTimeTotalAmount,
         Datepart(second, createstamp) / 5 AS dp
  FROM   [order]
  WHERE 
         createstamp BETWEEN Dateadd(s, -5, Getdate()) AND Getdate()
  GROUP  BY Datepart(second, createstamp) / 5  
  </code></pre>
  
  <p>The problem I am facing is, that it shows me the 'accumulative sum as per each second' and I want to see it like '(accumulative sum as per each second + total accumulative amount till that second)'</p>
  
  <p>Here is how the source data looks like:         </p>
  
  <pre><code>-----------------------------------------------------------
  |OrderID  | CreateStamp             | TotalAmount         |
  -----------------------------------------------------------
  |1        |2015-03-22 15:26:05.620  | 10                  |
  -----------------------------------------------------------
  |2        |2015-03-22 15:26:05.653  | 20                  |
  -----------------------------------------------------------
  |3        |2015-03-22 15:26:05.660  | 10                  |
  -----------------------------------------------------------
  |4        |2015-03-22 15:26:06.663  | 10                  |
  -----------------------------------------------------------
  |5        |2015-03-22 15:26:06.670  | 30                  |
  -----------------------------------------------------------
  </code></pre>
  
  <p>Essentially, I want the resulting query to return as follows:</p>
  
  <pre><code>----------------------------------------
  |Period          | Accumulative Amount | 
  ----------------------------------------
  |0 to 5 seconds  | 30                  |
  ----------------------------------------
  |0 to 10 seconds | 80                  |
  ----------------------------------------
  </code></pre>
  
  <p>This is basically an accumulation from 0 time to multiples of 5.for last 5 seconds basically i am calculating the amount for the whole day up to the time when i execute this query and for example the amount for whole day before this time was 50 so result table should look like </p>
  
  <pre><code>----------------------------------------
  |0 to 5 seconds  | 30 + 50 = 80        |
  ----------------------------------------
  |0 to 10 seconds | 80 + 80 = 160       |
  ----------------------------------------
  </code></pre>