当前位置: 代码迷 >> Oracle管理 >> 这么写为什么不能运行
  详细解决方案

这么写为什么不能运行

热度:67   发布时间:2016-04-24 04:17:49.0
这样写为什么不能运行啊
 select * from emp e1
left join dept
on dept.deptno=e1.deptno
where exists( 
select max(sal) m,deptno d  
from emp
where m=e1.sal and d=dept.deptno 
group by deptno

)
是通过emp和dept表求每个部门的里面工资最高的员工的信息
为什么我重命名的m d会报错
------解决方案--------------------


-- 这种别名的用法,ORACLE 不 支持。
select max(sal) m,deptno d  
from emp
where m=e1.sal and d=dept.deptno 
group by deptno

-- 这里提供一下语句,LZ 不妨试一下。    多列 in (多列) ,这样的用法。
 select * from emp e1
left join dept
on dept.deptno=e1.deptno
where (sal, deptno ) in ( 
select max(sal) m,deptno d  
from emp
group by deptno
)
-- 如果 LZ 觉的这个不好用,还有分析函数的用法,需要的话,可以直接回复我,或 baidu 一下。
  相关解决方案