資料庫查詢前N條記錄sql語句介紹

2021-05-25 00:54:11 字數 531 閱讀 9651

1.mssql

a)查詢前n條記錄:

select top n * from  table_name;

b)查詢第n條到第m條記錄:

select top n * from (select top m * from table_name order by column_name) a order by column_name desc

2. mysql

a) 查詢前n條記錄

select * from table_name limit 0,n

b) 查詢第n條到第m條

select * from table_name limit n,m

3.oracle

a)查詢前n條記錄

select * from table_name where rownumb)查詢第m條到第n條記錄:

select * from (select a.*,a.rownum rn from (select * from table_name)  a  where  a.rownumn

取資料庫表前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...

SQL語句查詢每個分組的前N條記錄的實現方法

生成測試資料 t if object id tempdb.dbo.t is notnull drop table t create table t id varchar 3 gid int,author varchar 29 title varchar 39 date datetime insert...

SQL查詢每個分組的前N條記錄

if object id tempdb.dbo.t is not null drop table t create table t id varchar 3 gid int,author varchar 29 title varchar 39 date datetime insert into t ...