Professional Documents
Culture Documents
14 rows selected.
SQL> ed
Wrote file afiedt.buf
14 rows selected.
14 rows selected.
SQL> cl scr
14 rows selected.
14 rows selected.
SQL> ed
Wrote file afiedt.buf
14 rows selected.
SQL> ed
Wrote file afiedt.buf
14 rows selected.
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 SELECT
2 Ename,
3 HireDate,
4 LAG(Sal, 1, 0)
5 OVER(ORDER BY HireDate) PreSal,
6 Sal CurrSal,
7 LEAD(Sal, 1, 0)
8 OVER(ORDER BY HireDate) NextSal
9* FROM Emp
SQL> /
14 rows selected.
SQL> cl scr
14 rows selected.
SQL> cl scr
14 rows selected.
SQL> cl scr
SQL> ed
Wrote file afiedt.buf
SQL> ed
Wrote file afiedt.buf
14 rows selected.
SQL> cl scr
SQL> ed
Wrote file afiedt.buf
SQL> ed
Wrote file afiedt.buf
SQL> R
1 SELECT E1.Deptno, E1.DeptSalSum,
2 ABS(E1.DeptSalSum - NextSal)||
3 DECODE(NVL(SIGN(E1.DeptSalSum - NextSal), 0),
4 1, ' More Budget Than Next Department',
5 -1, ' Less Budget Than Next Department',
6 0, ' Terminating Department') Remarks
7 FROM (SELECT Deptno, SUM(Sal) DeptSalSum,
8 LEAD(SUM(Sal), 1, NULL)
9 OVER(ORDER BY Deptno) NextSal
10 FROM Emp
11* GROUP BY Deptno) E1
14 rows selected.