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 t.A, t.B, t.C, ROW_NUMBER() OVER (ORDER BY t.A) as newId
2 FROM dbo.tableZ AS t
3 ORDER BY t.A;
1SELECT *
2FROM table
3WHERE condition
4GROUP BY expression
5HAVING condition
6{ UNION | INTERSECT | EXCEPT }
7ORDER BY expression
8LIMIT count
9OFFSET start
1Returns results where the row number meets the passed condition.
2Example: Returns the top 10 countries from the countries table.
3SELECT * FROM countries
4WHERE ROWNUM <= 10;
1syntax -> SELECT column_name(s)
2FROM table_name
3WHERE ROWNUM <= number
4////example///
5SELECT *
6FROM Persons
7WHERE ROWNUM <=5
1SELECT ROWNUM, a.*
2FROM (SELECT customers.*
3 FROM customers
4 WHERE customer_id > 4500
5 ORDER BY last_name) a;