View Single Post
  #2 (permalink)  
Old 05-23-2006, 11:59 PM
alexfr alexfr is offline
Junior Member
 
Join Date: May 2006
Posts: 24
alexfr is on a distinguished road
Default SQL 92 answer. Re: Create a third row that make the sum of past row + current row (i.e. a running sum)?

[sql]SELECT T2.WEEK, T2.TOTAL, COALESCE(SUM(T1.TOTAL), 0) AS T
FROM MY_TABLE T1
LEFT OUTER JOIN MY_TABLE T2
ON T1.WEEK < T2.WEEK
GROUP BY T2.WEEK, T2.TOTAL
ORDER BY 1 DESC[/sql]

Here I use the COALESCE function that will replace the NULL that can be found in some rows by 0 (otherwise the sum couldn't be done)
Reply With Quote