1、取前十條記錄
select top 10 id from dbo.sysobjects
2、取11條記錄到30條記錄
select top 20 * from dbo.sysobjects where id not in
(select top 10 id from dbo.sysobjects)
效能分析
set statistics io on;
set statistics time on;
select top 10 *
from (select top 20 * from sysobjects order by id) as tbl2
order by tbl2.id desc
cpu 時間 = 0 毫秒,耗費時間 = 12 毫秒。
(所影響的行數為 10 行)
表 'sysobjects'。掃瞄計數 1,邏輯讀 2 次,物理讀 0 次,預讀 0 次。
select top 10 *
from sysobjects
where id not in (select top 20 id from sysobjects)
cpu 時間 = 14 毫秒,耗費時間 = 14 毫秒。
(所影響的行數為 10 行)
表 'sysobjects'。掃瞄計數 2,邏輯讀 4 次,物理讀 0 次,預讀 0 次。
前者的效能,要好一些
Freemarker list物件取前幾條資料
專案中用freemarker 做顯示層,可能會遇到取出資料前幾條,通過用freemarker 取資料用 但是這種取法是取出所有的資料.如果我想去第一條資料 第一項的值 現在只想取前5條,該怎麼做?如下 定義n的值為list5的大小 如果n大於6,頁面中可能要求只顯示6條 注 gt,gte,lt,lt...
MySQL 分組後取前幾條
利用group concat和substring index實現,能很好的利用索引,適合大資料。select from yourtable where id in select substring index group concat id order by column 2 desc 1 id f...
Oracle 中取前幾條記錄 分頁
oracle中用於類似mssql中top的關鍵字為rownumber,具體用法如下 select firmcode,balance from select rownum rn,t.firmcode,t.balance from firmbalance tab t order by balance d...