如何从T-SQL中的表中选择前N行? [英] how to select first N rows from a table in T-SQL?
本文介绍了如何从T-SQL中的表中选择前N行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法选择,例如,在T-SQL(工作MSSQL)中的表的前10行?
我想我在Oracle中看到一些定义为rownum元变量,用于以下方式
select * from Users where rownum <= 10
但是MSSQL是什么?
解决方案
从用户选择top(@count)*
如果 @count
是常数,可以删除括号:
从用户中选择top 42 *
(后者适用于SQL Server 2000,而前者至少需要2005年)
Is there any way to select, for example, first 10 rows of a table in T-SQL (working MSSQL)?
I think I saw something in Oracle defined as rownum meta variable, used in a following way
select * from Users where rownum<=10
But what about MSSQL?
解决方案
select top(@count) * from users
If @count
is a constant, you can drop the parentheses:
select top 42 * from users
(the latter works on SQL Server 2000 too, while the former requires at least 2005)
这篇关于如何从T-SQL中的表中选择前N行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文