SQLServer SQL query with a row counter

后端 未结 4 1515
花落未央
花落未央 2021-02-01 05:09

I have a SQL query, that returns a set of rows:

SELECT id, name FROM users where group = 2

I need to also include a column that has an incremen

4条回答
  •  粉色の甜心
    2021-02-01 05:55

    In SQL Server 2005 and up, you can use the ROW_NUMBER() function, which has options for the sort order and the groups over which the counts are done (and reset).

提交回复
热议问题