首页 > 数据库技术 > 详细

MySQL的排序方式

时间:2018-03-18 14:18:41      阅读:260      评论:0      收藏:0      [点我收藏+]

MySQL中 进行排序的方式:

Select * from 表名 [where 条件 order by  字段名(默认的是ASC升序排列)]

ASC是升序排列,DESC用来指定降序排列

Oracle中子查询:

Select * from 表名 where 条件 (select * from 表名 where 条件)

 技术分享图片

 

实例:

in: select * from emp where deptno in (select deptno from dept where loc = ‘DALLAS‘ or loc = ‘BOSTOM‘);
all: select * from emp where sal > all(select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);
any: select * from emp where sal > any(select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);
exists: select * from emp where exists (select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);

 

union操作用于计算两个结果集的并集,它在取并集时会自动去掉结果集的重复行。
select * from emp where sal <= 1600 union select * from emp where sal >= 1500;
intersect操作于计算两个结果集的交集
select * from emp where sal <= 1600 intersect select * from emp where sal >= 1500;
minus操作用于计算两个结果集的差集(只返回在第一个结果集中存在,但在第二个集中不存在的数据)
select * from emp where sal <= 1600 minus select * from emp where sal >= 1500;

其他方法:

 技术分享图片

 

 

MySQL的排序方式

原文:https://www.cnblogs.com/darui/p/8595222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!