select并显示与用户提示的ename具有相同deptno和mgr的employess
select and display employess who have the same deptno and mgr as the prompted ename by the user
显示与给定员工(提示)具有相同DEPTNO和MGR的员工,不包括该员工。
谁能帮我解决这个问题并告诉我如何排除用户提供的员工。
select ename,deptno,mgr from emp where
deptno=(select deptno from emp where ename='&&ename')
AND
mgr=(select mgr from emp where ename='&ename');
例如:
SQL> select deptno, empno, ename, mgr
2 from emp
3 order by deptno, mgr;
DEPTNO EMPNO ENAME MGR
---------- ---------- ---------- ----------
10 7934 MILLER 7782
10 7782 CLARK 7839
10 7839 KING
20 7788 SCOTT 7566
20 7902 FORD 7566
20 7876 ADAMS 7788
20 7566 JONES 7839
20 7369 SMITH 7902
30 7521 WARD 7698 --> we'll watch these
30 7499 ALLEN 7698 -->
30 7844 TURNER 7698 -->
30 7900 JAMES 7698 -->
30 7654 MARTIN 7698 --> employees
30 7698 BLAKE 7839
14 rows selected.
查询:第 3 - 6 行 select 具有相同 DEPTNO
和 MGR
的人,而第 7 行排除了那个员工(由 PAR_EMPNO
标识) .
SQL> select e.*
2 from emp e
3 where (e.deptno, e.mgr) = (select a.deptno, a.mgr
4 from emp a
5 where a.empno = &&par_empno
6 )
7 and e.empno <> &&par_empno;
Enter value for par_empno: 7521
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 02/20/1981 1600 300 30
7654 MARTIN SALESMAN 7698 09/28/1981 1250 1400 30
7844 TURNER SALESMAN 7698 09/08/1981 1500 0 30
7900 JAMES CLERK 7698 12/03/1981 950 30
SQL>
显示与给定员工(提示)具有相同DEPTNO和MGR的员工,不包括该员工。 谁能帮我解决这个问题并告诉我如何排除用户提供的员工。
select ename,deptno,mgr from emp where
deptno=(select deptno from emp where ename='&&ename')
AND
mgr=(select mgr from emp where ename='&ename');
例如:
SQL> select deptno, empno, ename, mgr
2 from emp
3 order by deptno, mgr;
DEPTNO EMPNO ENAME MGR
---------- ---------- ---------- ----------
10 7934 MILLER 7782
10 7782 CLARK 7839
10 7839 KING
20 7788 SCOTT 7566
20 7902 FORD 7566
20 7876 ADAMS 7788
20 7566 JONES 7839
20 7369 SMITH 7902
30 7521 WARD 7698 --> we'll watch these
30 7499 ALLEN 7698 -->
30 7844 TURNER 7698 -->
30 7900 JAMES 7698 -->
30 7654 MARTIN 7698 --> employees
30 7698 BLAKE 7839
14 rows selected.
查询:第 3 - 6 行 select 具有相同 DEPTNO
和 MGR
的人,而第 7 行排除了那个员工(由 PAR_EMPNO
标识) .
SQL> select e.*
2 from emp e
3 where (e.deptno, e.mgr) = (select a.deptno, a.mgr
4 from emp a
5 where a.empno = &&par_empno
6 )
7 and e.empno <> &&par_empno;
Enter value for par_empno: 7521
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 02/20/1981 1600 300 30
7654 MARTIN SALESMAN 7698 09/28/1981 1250 1400 30
7844 TURNER SALESMAN 7698 09/08/1981 1500 0 30
7900 JAMES CLERK 7698 12/03/1981 950 30
SQL>