Home  >  Article  >  Database  >  Oracle中from中子查询实例应用

Oracle中from中子查询实例应用

WBOY
WBOYOriginal
2016-06-07 17:23:55991browse

Linux公社(www.linuxidc.com)是专业的Linux系统门户网站,实时发布最新Linux资讯,包括Linux、Ubuntu、Fedora、RedHat、红旗Linux、Linux教程、Linux认证、SUSE

Oracle表复杂查询
----------------------------------------------------------

字查询
from 中的子查询

例子:如何显示高于自己部门平均工工资的员工信息
思路:


1.查询出各个部门的平均工资和部门号


select deptno, avg(sal) mysal from emp group bydeptno;


2.把上面的查询结果看作是一张子表


select a2.ename ,a2.sal,a2.deptno ,a1.mysal from emp a2

(select deptno, avg(sal) mysal from emp group bydeptno) a1

where a2.deptno=a1.deptno and a2.sal >a1.mysal


这里需要说明的是当from字句中使用子查询时,,该子查询会被作为一个视图来对待,因此叫做内嵌视图,当在From字句中使用子查询时,必须给予查询指定别名。
别名不建议用as

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn