Oracle SQL子查询实例
1 查询工资高于公司平均水平的员工
这是平均工资;
示例的emp表是有14条记录;
2 查询部门的平均工资高于公司平均水平的部门
3 查询每个员工的部门名称
select * from emp e where sal > (select AVG(sal) FROM emp);
SELECT deptno, AVG(sal) as avg_sal
FROM emp
GROUP BY deptno
HAVING AVG(sal) > (SELECT AVG(sal) FROM emp);
SELECT ename, (SELECT dname FROM dept WHERE dept.deptno = emp.deptno) as department_name
FROM emp;