目录一、限制查询1.指定从第几行起,返回多少行2.取最大值3.取最小值4.分页二、数据排序1.年龄大于10的根据id进行降序排序2.年龄大于10的按照id进行升序排序一、限制查询 我
我们通过limit
可以限制返回结果的行数
select * from 表名 limit count;
select * from users limit 3;
select * from 表名 limit start,count;
select * from users limit 2,3;
相等
select * from users limit 3 offset 2;
select * from users order by age desc limit 1;
select * from users order by age asc limit 1;
select * from users limit (page-1)*pageSize,pageSize;
当数据查询出来以后,我们可以对数据进行排序处理。在末尾使用order by语句。
select * from 表名 order by 列1 asc|desc,列2 asc|desc,...
注:
- asc即为升序,也是默认值。
- desc即为降序
- 排序首先先按照列1进行排序,如果出现结果相同的,在进行列2排序
select * from users
where age > 10 order by id desc;
select * from users
where age > 10 order by id asc;
到此这篇关于Mysql限制查询和数据排序介绍的文章就介绍到这了,更多相关mysql限制查询数据排序内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: MySQL限制查询和数据排序介绍
本文链接: https://www.lsjlt.com/news/143871.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-26
2024-04-26
2024-04-26
2024-04-26
2024-04-26
2024-04-26
2024-04-24
2024-04-24
2024-04-24
2024-04-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0