wangwei6815 2011-11-21 13:20
浏览 425
已采纳

请高手看下这个语句为什么报缺少右括号的错误?

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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?