Home >Database >Mysql Tutorial >sql2005 根据指定字段排序编号

sql2005 根据指定字段排序编号

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 18:04:16945browse

在SQL Server 2005可以通过with as根据指定的字段排序编号

SQL语句如下:  
代码如下:
WITH 表1 AS
(
SELECT 编号字段名, ROW_NUMBER() OVER(ORDER BY 排序字段名 DESC) AS RowNum
FROM 表名
)
Update 表1
SET 编号字段名=RowNum

应用场景:
通过这样的SQL语句根据小组人气值对小组进行排名:
代码如下:
WITH groups AS
(
SELECT RankNum, ROW_NUMBER() OVER(ORDER BY 人气值 DESC) AS RowNum
FROM club_Groups
)
Update groups
SET RankNum=RowNum
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn