1-- Uses AdventureWorks
2
3SELECT ROW_NUMBER() OVER(ORDER BY SUM(SalesAmountQuota) DESC)
4 AS RowNumber,
5 FirstName, LastName,
6 CONVERT(varchar(13), SUM(SalesAmountQuota),1) AS SalesQuota
7FROM dbo.DimEmployee AS e
8INNER JOIN dbo.FactSalesQuota AS sq
9 ON e.EmployeeKey = sq.EmployeeKey
10WHERE e.SalesPersonFlag = 1
11GROUP BY LastName, FirstName;
12
1USE AdventureWorks2012;
2GO
3WITH OrderedOrders AS
4(
5 SELECT SalesOrderID, OrderDate,
6 ROW_NUMBER() OVER (ORDER BY OrderDate) AS RowNumber
7 FROM Sales.SalesOrderHeader
8)
9SELECT SalesOrderID, OrderDate, RowNumber
10FROM OrderedOrders
11WHERE RowNumber BETWEEN 50 AND 60;
12