必須是SQL Server 2005/ SQL server 9.0以上才可執行 SELECT c.FirstName, c.LastName ,ROW_NUMBER() OVER (ORDER BY a.PostalCode) AS 'Row Number' ,RANK() OVER (ORDER BY a.PostalCode) AS 'Rank' ,DENSE_RANK() OVER (ORDER BY a.PostalCode) AS 'Dense Rank' ,NTILE(4) OVER (ORDER BY a.PostalCode) AS 'Quartile' ,s.SalesYTD, a.PostalCode FROM Sales.SalesPerson s INNER JOIN Person.Contact c ON s.SalesPersonID = c.ContactID INNER JOIN Person.Address a ON a.AddressID = c.ContactID WHERE TerritoryID IS NOT NULL AND SalesYTD <> 0; output: FirstName, LastName, Row Number, Rank, Dense Rank, Quartile, SalesYTD, PostalCode Maciej Dusza 1 1 1 1 4557045.0459 98027 Shelley Dyck 2 1 1 1 5200475.2313 98027 Linda Ecoffey 3 1 1 1 3857163.6332 98027 Carla Eldridge 4 1 1 1 1764938.9859 98027 Carol Elliott 5 1 1 2 2811012.7151 98027 Jauna Elson 6 6 2 2 3018725.4858 98055 Michael Emanuel 7 6 2 2 3189356.2465 98055 Terry Eminhizer 8 6 2 3 3587378.4257 98055 Gail Erickson 9 6 2 3 5015682.3752 98055 Mark Erickson 10 6 2 3 3827950.238 98055 Martha Espinoza 11 6 2 4 1931620.1835 98055 Janeth Esteves 12 6 2 4 2241204.0424 98055 Twanna Evans 13 6 2 4 1758385.926 98055