一尘不染

SELECT TOP 1的ANSI SQL版本

sql

是否有符合ANSI SQL的SQL SERVER版本SELECT TOP n


阅读 157

收藏
2021-03-10

共1个答案

一尘不染

ANSI / ISO SQL:2003引入了 窗口函数

SELECT * FROM (
  SELECT
    ROW_NUMBER() OVER (ORDER BY age ASC) AS rownum,
    person_id,
    person_name,
    age
  FROM person
) AS foo
WHERE rownum <= 3

自SQL Server 2005起,Microsoft SQL Server就支持此语法。http: //msdn.microsoft.com/zh-
cn/library/ms189798(v=sql.90).aspx

ANSI / ISO SQL:2008为引入了一种更简单的语法FETCH FIRST,该语法可能更类似于Microsoft /
SybaseTOP语法:

SELECT person_id, person_name, age FROM person
FETCH FIRST 3 ROWS ONLY

Microsoft尚不支持此语法。另请参见http://en.wikipedia.org/wiki/Select_(SQL)#Limiting_result_rows

2021-03-10