1USE AdventureWorks2012;
2GO
3SELECT FirstName, LastName, TerritoryName, ROUND(SalesYTD,2,1) AS SalesYTD,
4ROW_NUMBER() OVER(PARTITION BY TerritoryName ORDER BY SalesYTD DESC)
5 AS Row
6FROM Sales.vSalesPerson
7WHERE TerritoryName IS NOT NULL AND SalesYTD <> 0
8ORDER BY TerritoryName;
9
1SELECT
2 ROW_NUMBER() OVER (
3 ORDER BY first_name
4 ) row_num,
5 first_name,
6 last_name,
7 city
8FROM
9 sales.customers;
10
1ROW_NUMBER() OVER (ORDER BY 'Column_Name' DESC) as ROW_NUMBER
2
3
4select ROW_NUMBER() OVER(PARTITION BY WorkOrderID ORDER BY WorkOrderID ASC)
5 AS Row#, * from TableName
1
2
3
4
5 SELECT
6 ROW_NUMBER() OVER (
7 ORDER BY first_name
8 ) row_num,
9 first_name,
10 last_name,
11 city
12FROM
13 sales.customers;
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