Oracle - LEAD Function
最近在做 Project 時遇到資料是要 Row 的資料做相減的話,故如何使用 SQL 要如何達到此功能呢?在 Oracle 中有提供 LEAD Function,可以達到此功能. Syntax >──LEAD (value_expr─┬─────────┬─┬──────────┬─)───────────> └─,offset─┘ └─,default─┘ >──OVER (─┬────────────────────────┬─order_by_clause)───>< └─query_partition_clause─┘ Example The following example provides, for each employee in the emp table, the hiredate of the employee hired just after: SELECT ename, hiredate, LEAD(hiredate, 1) OVER (ORDER BY hiredate) AS "NextHired" FROM emp; ENAME HIREDATE NextHired ---------- --------- --------- SMITH 17-DEC-80 20-FEB-81 ALLEN 20-FEB-81 22-FEB-81 WARD 22-FEB-81 02-APR-81 ...