sql SELECT TOP.sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SELECT TOP.sql相关的知识,希望对你有一定的参考价值。

/* allows you to select the first number of rows from a table. 
Good for seing what's in the table (columns, etc.) without having to pull the whole table.

If you use with an ORDER BY clause, it'll have to read the entire table, sort, and then selet the TOP number of rows.
Therefore, there isn't a cost savings if you use TOP with an ORDER BY that is not the index column.

*/

--the full standard uses () around the number in the top
SELECT TOP (20) * FROM customers1;


-- however, you can omit the (), but that is apparently only for backward compatibility - it's safer to use ()
SELECT TOP 50 * FROM customers1;

--you can also specify a percent
--SQL Server will round up (ceiling) if the percentage returns a decimal place.
--example: if 5% of your table is 9.2 rows, it'll return 10 rows
SELECT TOP (5) PERCENT * FROM t_appeal;

以上是关于sql SELECT TOP.sql的主要内容,如果未能解决你的问题,请参考以下文章

Oracle top 查询TOP SQL

sql get_top_record.sql

db2查看top sql

SQL 'select' 和 PL/SQL 'select' 语句有啥区别?

sql 使用SELECT * INTO或SELECT INTO.sql复制表

SQL SELECT 语句