Oracle update和order by

來源:互聯網
上載者:User

Oracle update和order by

今天遇到一個關於SQL轉換成Oracle語句的問題,描述如下:

select * from emp order by deptno;

select * from dept;

Sql Server:

update dept a set dname=(select top 1 ename from emp where deptno=a.deptno order by sal)

經過嘗試,尋找資料,得出下面轉換結果,不知道這樣是否可行:

update dept a set dname=

(with t as(select ename,deptno from emp order by sal)

select ename from t where deptno=a.deptno and rownum=1)

where exists(with t as(select ename,deptno from emp order by sal)

select null from t where deptno=a.deptno)

執行結果:

select * from dept;

其他替代方法隨後再做嘗試。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.