今天遇到一個關於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;
其他替代方法隨後再做嘗試。