Home > Database > Mysql Tutorial > sql server2008 排序函数

sql server2008 排序函数

WBOY
Release: 2016-06-07 16:19:44
Original
976 people have browsed it

排序函数: 1.row_number() over(order by liename):根据order by后面的字段排序,为每一行给定一个唯一的行号 select row_number() over( order by iname desc ) as rowid ,iname from test 2.Rank():根据order by 后面的字段排序,order by后面的字段值

   排序函数:

  1.row_number() over(order by liename):根据order by后面的字段排序,为每一行给定一个唯一的行号

  select row_number() over( order by iname desc ) as rowid ,iname from test

sql server2008 排序函数 三联

  2.Rank():根据order by 后面的字段排序,order by后面的字段值相同序号就相同,序号可能是不连续的

  select distinct rank() over( order by iname desc ) as rowid ,iname,iage from test

sqlserver2008 排序函数!

  3. dense_rank():根据order by 后面的字段排序,order by后面的字段值相同序号就相同,序号是连续的

  select distinct dense_rank() over( order by iname desc ) as rowid ,iname from test

sqlserver2008 排序函数!

  4. ntile():先根据order by 后面对的字段排序,然后将排序结果分成规定的几个组,,并为每个组指定一个组号

  select distinct ntile(5) over( order by iname desc ) as rowid ,iname,iage from test order by rowid

sqlserver2008 排序函数!

  总结:

  1.row_number() over(order by liename):根据order by后面的字段排序,为每一行给定一个唯一的行号

  2.Rank():根据order by 后面的字段排序,order by后面的字段值相同序号就相同,序号可能是不连续的

  3. dense_rank():根据order by 后面的字段排序,order by后面的字段值相同序号就相同,序号是连续的

  4. ntile():先根据order by 后面对的字段排序,然后将排序结果分成规定的几个组,并为每个组指定一个组号

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