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
Showing posts with label ROWS BETWEEN. Show all posts
Showing posts with label ROWS BETWEEN. Show all posts
Tuesday, April 9, 2013
TSQL Difference between 2 rows
use AdventureWorks2012;
Labels:
AdventureWorksDW,
AGGREGATE,
OVER,
PARTITON BY,
ROWS BETWEEN,
SUM
Subscribe to:
Posts (Atom)