当前第2页 返回上一页
1、单行查询
1 2 3 4 5 6 7 8 9 10 11 |
select * from emp
where sal > (select avg(sal) from emp)
select * from emp e
where e.deptno=(select d.deptno from dept d where d.deptno=1 )
|
2、多行查询
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
select * from emp e
where e.deptno in(select d.deptno from dept d)
select * from emp e
where e.sal < any(select sal from emp where deptno=2)
select * from emp e
where e.sal < all(select sal from emp where deptno=2)
|
三、聚合查询(求和,平均,记录总数)
1、求和,平均查询
1 2 3 4 5 |
select sum(sal),avg(sal) from emp
select avg(nvl(sal,0)) from emp
|
2、记录总数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
select count (*) from emp
select count (memo) from emp
select count (distinct(sex)) from emp
select e.deptno,sum(e.sal)
from emp e
group by e.deptno
select e.deptno,avg(e.sal)
from emp e
group by e.deptno
having avg(e.sal) > 4500
|
相关学习推荐:mysql视频教程
以上就是多表查询有几种方式的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
mysql navicat怎么删除数据库
学习mysql如何优化查询速度
mysql如何通过实例化对象参数查询数据 ?(源代码)
mysql连接查询左连接,右连接,内连接实例详解
centos7 mysql 5.6 多主一从 解决方案与详细配置
总结mysql数据库与表的基本常用命令
mysql中关于主从数据库同步延迟的问题解决
怎么查看mysql的安装路径?
如何解决mysql报错“#1067 invalid default value”
mysql精粹系列(精粹)
更多相关阅读请进入《mysql》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » 多表查询有几种方式