Home > Database > Mysql Tutorial > body text

[数据库]ROW_NUMBER()OVER函数的基本用法

WBOY
Release: 2016-06-07 15:59:12
Original
1517 people have browsed it

(1)ROW_NUMBER() OVER(ORDER BY COLUMN) 通常,开发者和管理员在一个查询里,用临时表和列相关的子查询来计算产生行号。现在SQL Server 2005提供了一个函数,代替所有多余的代码来产生行号。 简单的说row_number()从1开始,为每一条分组记录返回一个数字,

(1)ROW_NUMBER() OVER(ORDER BY COLUMN)

通常,开发者和管理员在一个查询里,用临时表和列相关的子查询来计算产生行号。现在SQL Server 2005提供了一个函数,代替所有多余的代码来产生行号。

简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把CourseID列降序,再为降序以后的没条xlh记录返回一个序号。

select ROW_NUMBER() over(order by CourseID desc) as RowIndex,* from TeacherRoles where ClassCode = '111111111113710401'


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!