SQL: Numbering the rows returned by a SELECT statement

前端 未结 6 2219
说谎
说谎 2021-01-06 06:26

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 FR

6条回答
  •  青春惊慌失措
    2021-01-06 06:53

    SQL 2005, 2008:

    SELECT TOP 3 ROW_NUMBER() OVER(ORDER BY NumberOfVotes DESC) AS VoteRank, Name FROM PuppyNames

    EDIT: Sorry - just saw you specified 2000.

提交回复
热议问题