ROW_NUMBER
Returns the sequential number of
a row within a partition of a result set, starting at 1 for the first row in
each partition.
Example :
USE AdventureWorks2012;
GO
SELECT
ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS
Row,
FirstName,
LastName,
ROUND(SalesYTD,2,1) AS "Sales YTD"
FROM
Sales.vSalesPerson
WHERE
TerritoryName IS NOT NULL AND SalesYTD
<> 0;
Remarks:-
There is no guarantee that the rows returned by a query using
ROW_NUMBER() will be ordered exactly the same with each execution unless the
following conditions are true.
- Values of the partitioned column are unique.
- Values of the ORDER BY columns are unique.
- Combinations of values of the partition column and ORDER BY columns are unique.
No comments :
Post a Comment