Home > Database > Mysql Tutorial > body text

SqlServer2000 类似sqlserver2005的 rownumber() 函数

WBOY
Release: 2016-06-07 15:27:29
Original
1448 people have browsed it

rownumber() 是SqlServer2005新增加的一个函数,主要是用于解决表排序的序列号的问题。而SqlServer2000 没有这样的函数,那遇到这样的情况我们怎么解决呢? 如下: sqlserver2005 : SELECT row_number() OVER (ORDER BY t .AgentIdentify ASC, t .AgentLevel

rownumber() 是SqlServer2005新增加的一个函数,主要是用于解决表排序的序列号的问题。而SqlServer2000 没有这样的函数,那遇到这样的情况我们怎么解决呢?

 

如下:

sqlserver2005 :    SELECT     row_number() OVER (ORDER BY t .AgentIdentify ASC, t .AgentLevelRate DESC) AS row
, t .* FROM (SELECT  top 20 * FROM    AgentLevel  ORDER BY AgentIdentify ASC, AgentLevelRate DESC) t

 

 

sqlserver2000:   SELECT     (select count(*) from AgentLevel where AgentLevelRate >=t.AgentLevelRate) AS row
, t .* FROM (SELECT  top 20 * FROM    AgentLevel  ORDER BY AgentIdentify ASC, AgentLevelRate DESC) t

 

看出我们只需要用 自连接 便可以解决 sqlserver2000 没有rownumber()的问题。

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