<font face="NSimsun">/*以下示例将根据年初至今的销售额,返回 AdventureWorks 中销售人员的 ROW_NUMBER。*/</font>
<font face="NSimsun"> </font>
<font face="NSimsun">USE AdventureWorks </font>
<font face="NSimsun">GO </font>
<font face="NSimsun">SELECT</font> c.FirstName, c.LastName, ROW_NUMBER() OVER( ORDER <font face="NSimsun">BY</font> SalesYTD DESC ) AS 'Row Number' , s.SalesYTD, a.PostalCode
<font face="NSimsun">FROM</font> Sales.SalesPerson s JOIN Person.Contact c on <font face="NSimsun">s.SalesPersonID = c.ContactID </font>
<font face="NSimsun">JOIN</font> Person.Address a ON <font face="NSimsun">a.AddressID = c.ContactID </font>
<font face="NSimsun">WHERE</font> TerritoryID IS <font face="NSimsun">NOT</font> <font face="NSimsun">NULL</font> <font face="NSimsun">AND</font> <font face="NSimsun">SalesYTD 0 </font>
<font face="NSimsun">/* </font>
<font face="NSimsun">FirstName LastName Row Number SalesYTD PostalCode </font>
<font face="NSimsun">--------- ---------- ---------- ------------ ---------------------------- </font>
<font face="NSimsun">Shelley Dyck 1 5200475.2313 98027 </font>
<font face="NSimsun">Gail Erickson 2 5015682.3752 98055 </font>
<font face="NSimsun">Maciej Dusza 3 4557045.0459 98027 </font>
<font face="NSimsun">Linda Ecoffey 4 3857163.6332 98027 </font>
<font face="NSimsun">Mark Erickson 5 3827950.238 98055 </font>
<font face="NSimsun">Terry Eminhizer 6 3587378.4257 98055 </font>
<font face="NSimsun">Michael Emanuel 7 3189356.2465 98055 </font>
<font face="NSimsun">Jauna Elson 8 3018725.4858 98055 </font>
<font face="NSimsun">Carol Elliott 9 2811012.7151 98027 </font>
<font face="NSimsun">Janeth Esteves 10 2241204.0424 98055 </font>
<font face="NSimsun"> </font>
<font face="NSimsun">Martha Espinoza 11 1931620.1835 98055 </font>
<font face="NSimsun">Carla Eldridge 12 1764938.9859 98027 </font>
<font face="NSimsun">Twanna Evans 13 1758385.926 98055 </font>
<font face="NSimsun">(13 行受影响) </font>
<font face="NSimsun">*/</font>
<font face="NSimsun"> </font>
<font face="NSimsun">/*以下示例将返回行号为 50 到 60(含)的行,并以 OrderDate 排序。*/</font>
<font face="NSimsun">USE AdventureWorks; </font>
<font face="NSimsun">GO </font>
<font face="NSimsun">WITH</font> OrderedOrders AS
( SELECT <font face="NSimsun">SalesOrderID, OrderDate, </font>
ROW_NUMBER() OVER ( order <font face="NSimsun">by</font> OrderDate) as <font face="NSimsun">RowNumber </font>
<font face="NSimsun">FROM</font> <font face="NSimsun">Sales.SalesOrderHeader ) </font>
<font face="NSimsun">SELECT</font> <font face="NSimsun">* </font>
<font face="NSimsun">FROM</font> <font face="NSimsun">OrderedOrders </font>
<font face="NSimsun">WHERE</font> RowNumber between 50 and <font face="NSimsun">60; </font>
<font face="NSimsun">/* </font>
<font face="NSimsun">SalesOrderID OrderDate RowNumber </font>
<font face="NSimsun">------------ ----------------------- -------------------- </font>
<font face="NSimsun">43708 2001-07-03 00:00:00.000 50 </font>
<font face="NSimsun">43709 2001-07-03 00:00:00.000 51 </font>
<font face="NSimsun">43710 2001-07-03 00:00:00.000 52 </font>
<font face="NSimsun">43711 2001-07-04 00:00:00.000 53 </font>
<font face="NSimsun">43712 2001-07-04 00:00:00.000 54 </font>
<font face="NSimsun">43713 2001-07-05 00:00:00.000 55 </font>
<font face="NSimsun">43714 2001-07-05 00:00:00.000 56 </font>
<font face="NSimsun">43715 2001-07-05 00:00:00.000 57 </font>
<font face="NSimsun">43716 2001-07-05 00:00:00.000 58 </font>
<font face="NSimsun">43717 2001-07-05 00:00:00.000 59 </font>
<font face="NSimsun">43718 2001-07-06 00:00:00.000 60 </font>
<font face="NSimsun">(11 行受影响) </font>
<font face="NSimsun">*/</font>
|