select t2.empno,t2.ename,t2.sal from emp t2 where t2.sal =(select max(t.sal) from emp t group by t.deptno order by t.deptno);
4条回答 默认 最新
- 爱上一条鱼 2011-11-21 13:31关注
select t2.empno,t2.ename,t2.sal from emp t2 where t2.sal =(select max(t.sal) from emp t group by t.deptno order by t.deptno);
你这句sql里, 后面的select子句会select出多个max(t.sal)记录的,虽然不知道为啥是括号错误,但是 t2.sal =(select xxxx)肯定是有问题的。
应该用in,另外子句也不需要order by,要排序也应该是对最后的结果排序 放在外面吧
[code="java"]select t2.empno,t2.ename,t2.sal from emp t2 where t2.sal in (select max(t.sal) from emp t group by t.deptno) order by t2.sal;[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报