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

sql2005 根据指定字段排序编号

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 18:04:16
Original
943 people have browsed it

在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
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template