selectTill Next Time
CustomerID,
OrderDate,
TotalDue,
sum(Totaldue) over(partition by CustomerId order by OrderDate Desc ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING ) as LastOrderAmount,
TotalDue - sum(Totaldue) over(partition by CustomerId order by OrderDate Desc ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING ) as ChangeFromLastOrder from sales.SalesOrderHeader
order by CustomerID, OrderDate Desc
Tuesday, April 9, 2013
TSQL Difference between 2 rows
use AdventureWorks2012;
Labels:
AdventureWorksDW,
AGGREGATE,
OVER,
PARTITON BY,
ROWS BETWEEN,
SUM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment