您需要使用LEAD()。
更正按照「a_horse_with_no_name的評論:鉛(SAL,1,SAL)
UPDATE emp_test a
SET sal =
(
SELECT LEAD(sal, 1, sal) OVER (ORDER BY sal) AS sal_next
FROM scott.emp b
WHERE a.empno = b.empno
)
/
同樣的,爲ename:
SELECT empno, ename, job, sal,
LEAD(ename, 1, ename) OVER (ORDER BY ename) AS name_next
FROM scott.emp
/
EMPNO ENAME JOB SAL NAME_NEXT
--------------------------------------------
7876 ADAMS CLERK 1100 ALLEN
7499 ALLEN SALESMAN 1600 BLAKE
7698 BLAKE MANAGER 2850 CLARK
7782 CLARK MANAGER 2450 FORD
....
7844 TURNER SALESMAN 1500 WARD
7521 WARD SALESMAN 1250 WARD
這是行不通的:
SELECT * FROM scott.emp
WHERE ROWNUM = 5
/
但是,這將會:
SELECT * FROM scott.emp
WHERE ROWNUM <= 5
/
來源
2013-03-15 17:27:29
Art
要做你正在嘗試,你將不得不做自我加入。您還必須與表格中的最後一行進行抗衡。說了這麼多,可能有更好的方法來實現你的目標。我無法想到我的頭頂。 – 2013-03-15 17:26:15