SQL Server
先从想要的数据处理加上Row_number()来为数据的row加上一个RowNum作为有多少条数据,然后再用BETWEEN来分隔 with t1 as (select * , Row_number() OVER (ORDER BY userId DESC) AS RowNum from users) SELECT *FROM t1 WHERE RowNum BETWEEN ((page-1)*rows+1) AND (page*rows) Oralce数据库 从数据库表中第M条记录开始检索N条记录 SELECT * FROM (SELECT ROWNUM r,t1.* From 表名称 t1 where rownum < M + N) t2 where t2.r >= M 例如从表Sys_option(主键为sys_id)中从10条记录还是检索20条记录,语句如下: SELECT * FROM (SELECT ROWNUM R,t1.* From Sys_option where rownum < 30 ) t2 Where t2.R >= 10 MySQL数据库 My SQL数据库最简单,是利用mySQL的LIMIT函数,LIMIT [offset,] rows从数据库表中M条记录开始检索N条记录的语句为: SELECT * FROM 表名称 LIMIT M,N 例如从表Sys_option(主键为sys_id)中从10条记录还是检索20条记录,语句如下: select * from sys_option limit 10,20
时间: 2024-10-12 20:12:18