O'Reilly logo
  • Dustin Waybright thinks this is interesting:

SELECT custid, orderid, orderdate, val,
  SUM(val) OVER(PARTITION BY custid
                ORDER BY orderdate, orderid
                ROWS BETWEEN UNBOUNDED PRECEDING
                         AND CURRENT ROW) AS runningtotal
FROM Sales.OrderValues;

From

Cover of Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012

Note

ORDER BY is ASC by default and since the window is between the current row (being processed) and the one preceding, it will generate a running total up to the most recent order.