用户登录
用户注册

分享至

sql top n查找前n项

  • 作者: 占戈灬礻申
  • 来源: 51数据库
  • 2021-08-01
sql top n查找前n项

 

sql top n

查找前n项

 

方法1、mysql> select * from table limit 20,10;  // 检索记录行 21-30  
//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:  
mysql> select * from table limit 95,-1; // 检索记录行 96-last.  
//如果只给定一个参数,它表示返回最大的记录行数目:  
mysql> select * from table limit 5;     //检索前 5 个记录行  
//换句话说,limit n 等价于 limit 0,n  

方法2 、top n
方法3、

select  * from   
(select  *,  row_number() over (order by id)  as rownum from  表) t
where  rownum between  21  and ​30

 


软件
前端设计
程序设计
Java相关