|

楼主 |
发表于 2006-6-9 11:05:17
|
显示全部楼层
SELECT last_name, salary, department_id
FROM employees outer
WHERE salary >
(SELECT AVG(salary)
FROM employees
WHERE department_id =
outer.department_id);
执行上面这句前我先查询了平均工资(select avg(salary) from employees),但是查出的第一条记录是小于avg(salary),其他记录都都大于avg(salary),这是为什么
SQL> select ename,sal,deptno from emp outer where sal>(select avg(sal) from emp where deptno=outer.deptno);
ENAME SAL DEPTNO
---------- ---------- ----------
[color="Red"]ALLEN 1600 30
JONES 2975 20
BLAKE 2850 30
SCOTT 3000 20
KING 5000 10
FORD 3000 20 |
|