是否存在符合ANSI SQL的版本的SQL SERVER SELECT TOP n
?
答案 0 :(得分:16)
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
Microsoft SQL Server自SQL Server 2005以来一直支持此语法。 http://msdn.microsoft.com/en-us/library/ms189798(v=sql.90).aspx
ANSI / ISO SQL:2008为FETCH FIRST
引入了一种更简单的语法,它可能更类似于Microsoft / Sybase TOP
语法:
SELECT person_id, person_name, age FROM person
FETCH FIRST 3 ROWS ONLY
Microsoft尚不支持此语法。另请参阅http://en.wikipedia.org/wiki/Select_(SQL)#Limiting_result_rows
如果您仍在使用Microsoft SQL Server 2000,那么您应该阅读我之前发布的关于执行“分页”样式查询的问题: Emulate MySQL LIMIT clause in Microsoft SQL Server 2000
答案 1 :(得分:0)
'LIMIT'与Amazon的Athena兼容:
SELECT * FROM myTable LIMIT 3;