0

I need to join both deptno and sal same time when comm is not null. I came up with following. But it only accept either deptno or sal. not both in same time.

select ename,deptno,sal,comm from emp where deptno,sal in(select sal,deptno from emp where comm is not null);

This is a self join.

I am trying it on oracle 10g

Thanks in advance.

4

3 回答 3

0

You could use a real join:

SELECT e1.ename, e1.deptno, e1.sal, e1.comm
FROM emp e1
JOIN (SELECT distinct sal, deptno
      FROM emp
      WHERE comm IS NOT NULL) e2
ON e1.sal = e2.sal AND e1.deptno = e2.deptno
于 2013-06-05T15:24:06.243 回答
0

您的目的尚不清楚,尽管您似乎想使用IN. 在这种情况下,您可以简单地添加括号:

SELECT ename, deptno, sal, comm 
  FROM emp 
 WHERE (sal, deptno) IN (SELECT sal, deptno FROM emp WHERE comm IS NOT NULL);
于 2013-06-05T15:10:13.297 回答
-1

你的查询不应该是这样的

select ename,deptno,sal,comm from emp where deptno,sal in(select deptno ,sal
from emp where comm is not null);
于 2013-06-05T15:09:22.570 回答