SQL: Numbering the rows returned by a SELECT statement
问题 Suppose I have a SELECT statement that returns some set of results. Is there some way I can number my results in the following way: SELECT TOP 3 Name FROM PuppyNames ORDER BY NumberOfVotes would give me... Fido Rover Freddy Krueger ...but I want... 1, Fido 2, Rover 3, Freddy Krueger where of course the commas signify that the numbers are in their own column. [I am using SQL Server 2000.] 回答1: In Microsoft SQL Server 2005, you have the ROW_NUMBER() function which does exactly what you want. If