各種資料庫取前幾行資料的例子

2021-07-10 03:27:04 字數 526 閱讀 1470

oracle的sql語句中既不能用limit也不能用top、

查第一行資料:

select * from

table

where rownum<2;

查第二行資料:

select * from

table

where rownum<3 minus select * from

table

where rownum<2;

查第一行資料:

select * from table limit 0,1

//從0+1條資料起,取一條資料

查第二行資料:

select * from table limit 1,1

//從1+1條資料起,取一條資料

select top n * from table

//返回前n行資料

各種資料庫取前10行記錄

各種資料庫取前10行記錄 收藏 access select top 10 from table1 where 1 1 db2 select column from table where 1 1 fetchfirst 10 rows only 取第三行到第5行的記錄 select from sele...

mysql取前幾行資料limit用法

在mysql中是沒有top關鍵字的,在mysql中可以用limit來完成功能。order by id desc limit 10 按照id的倒序排序 取出前10條 order by id desc limit 0,10 按照id的倒序排序 取出前10條 order by id limit 5,10 ...

sql server 分組,取每組的前幾行資料

sql中group by後,獲取每組中的前n行資料,目前我知道的有2種方法 比如有個成績表 裡面有欄位學生id,科目,成績。我現在想取每個科目的頭三名。1.子查詢 select from score s where studentname in select top 3 studentname fr...