sql 取表的前10條記錄,任意中間幾行的記錄

2021-07-05 19:34:07 字數 1256 閱讀 8273

取表的前10條記錄

with a as(select *,row_number()over(order by department)rn from _succeedstaff )

select * from a where rn<=10

取表的任意中間幾行的記錄eg:10-30

with a as(select *,row_number()over(order by department)rn from _succeedstaff )

select * from a where rn>=10 and rm<=30

附:常用幾種資料庫,取前10條記錄的sql語句寫法

access:

select top (10) * from table1 where 1=1

db2:

select column from table where 1=1 fetch first 10 rows only

mysql:

select * from table1 where 1=1 limit 10

sql server:

讀取前10條:select top (10) * from table1 where 1=1

讀取後10條:select top (10) * from table1 order by id desc

oracle:

select * from table1 where rownum<=10

取每日日期的前十條記錄

sql表列如下:

單號 日期

1 2011-09-10

2 2011-09-10

select * from tb a where 單號 in(select top 10 單號 from tb where 日期=a.日期 order by 單號)
select * from (

select *,rank () over(partition by day(日期) order by 日期) rk from tb

) twhere t.rk<=10

select * from(select *,row_number()over(order by name)rn from _succeedstaff )t

where t.rn<=10(對比上面)

取資料庫表前N條記錄,對於的SQL

取一表前n條記錄,各個資料庫的sql寫法 1.oracle select from table1 where rownum n 2.db2 select row number over order by col1 desc as rownum where rownum n db2 select co...

分組取前n條記錄的實現

在oracle中有一資料表exam result 成績記錄表 表中的一條記錄描述了 某個班某個學生某次考試的成績 create table exam result id number 10 not null,主鍵 classid number 10 not null,班級id,關聯到班級表 user...

從表中取20 30條記錄的SQL語句

mysql的方法 mysql select from student limit 20,10 sid studentid age name 21 00010014 13 10014 0 22 00010015 16 10015 2 23 00010016 27 10016 0 24 00010017...