title: Running total (COUNT) SQL Server
body: <p>I currently have this result</p>
  
  <pre><code> ID Code
   1  AAA12
   2  F5
   3  GOFK568
   4  G77
   5  JLKJ4
   6  FOG0
  </code></pre>
  
  <p>Now what i want to do is to create a third column that keeps a running total for codes that are above 4 in length.</p>
  
  <p>Now, i have this code that gives me the sum of the code with above 4 in length.</p>
  
  <pre><code> SELECT * ,
   SUM(CASE WHEN LENGTH(CODE) &gt; 4 THEN 1 ELSE 0 END) AS [Count]
   FROM Table1;
  </code></pre>
  
  <p>But this gives me this result</p>
  
  <pre><code> ID Code    Count
   1  AAA12   3
  </code></pre>
  
  <p>I am looking for a result like this </p>
  
  <pre><code> ID Code    Running_Total
   1  AAA12         1
   2  F5            1
   3  GOFK568       2
   4  G77           2
   5  JLKJ4         3
   6  FOG0          3
  </code></pre>
  
  <p>I was working on something similar to this</p>
  
  <pre><code> SELECT * ,
   CASE WHEN LENGTH(CODE) &gt; 4 THEN (SUM(Code) OVER (PARTITION BY ID)) ELSE END 
   AS [Count]
   FROM Table1;
  </code></pre>
  
  <p>But it still doesn't give me a running total.</p>
  
  <p>I have an SQL Fiddle page</p>
  
  <p><a href="http://sqlfiddle.com/#!9/2746c/18" rel="nofollow noreferrer">http://sqlfiddle.com/#!9/2746c/18</a></p>
  
  <p>Any help would be great</p>