当前第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执行计划的深入分析
mysql如何获取当前时间
mysql添加分区出错怎么办?
mysql如何实现自增序列
php连接mysql数据库方法简化版
mysql怎么创建索引
mysql官网如何下载源码包?
mysql建表语句是什么
mysql的内外查询分别是什么?
mysql 数据库函数库
更多相关阅读请进入《mysql》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » 多表查询有几种方式