NOVOTS KMS 词汇表 Glossary    联系我们 Contact Us
查询 Search  
   
按类别浏览 Browse by Category
NOVOTS KMS .: 数据库 .: SQLSERVER2005的ROW_NUMBER具体使用

SQLSERVER2005的ROW_NUMBER具体使用

row_number函数的用途是非常广泛,这个函数的功能是为查询出来的每一行记录生成一个序号

用法:

SELECT c.FirstName, c.LastName, ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS 'Row Number', s.SalesYTD, a.PostalCode

FROM Sales.SalesPerson s JOIN Person.Contact c on s.SalesPersonID = c.ContactID

JOIN Person.Address a ON a.AddressID = c.ContactID

WHERE TerritoryID IS NOT NULL AND SalesYTD <> 0

结果

FirstName  LastName    Row Number  SalesYTD      PostalCode
---------  ----------            ----------          ------------       ----------------------------
Shelley    Dyck            1                 5200475.2313            98027
Gail       Erickson         2                 5015682.3752            98055
Maciej     Dusza          3                4557045.0459             98027
Linda      Ecoffey        4                3857163.6332             98027
Mark       Erickson      5                 3827950.238               98055
Terry      Eminhizer     6                3587378.4257             98055
Michael    Emanuel      7                3189356.2465             98055
Jauna      Elson            8                3018725.4858             98055
Carol      Elliott            9                2811012.7151             98027
Janeth     Esteves        10               2241204.0424             98055
Martha     Espinoza     11               1931620.1835             98055
Carla      Eldridge        12               1764938.9859             98027
Twanna     Evans        13               1758385.926              98055


这篇文章对你多有用?


.: .: .: .: .:
[ 登陆 ]
北京护航科技有限公司 2006

Novots Technologies Limited