I have a source table like,
Empno ename sal
------- ---------- ----------
7001 kumar 0
7499 allen 2000
7521 ward 1250
7654 martin 1250
7698 blake 2850
7782 clark 2450
7839 king 6000
7844 turner 1500
7900 james 950
7934 miller 2000
Now my target table should look like,
Empno ename sal prevsal
------- -------- ------ ----------
7001 kumar 0 null
7499 allen 2000 0
7521 ward 1250 2000
7654 martin 1250 1250
7698 blake 2850 1250
7782 clark 2450 2850
7839 king 6000 2450
7844 turner 1500 6000
7900 james 950 1500
7934 miller 2000 950
Solution:
Using 'lag' function in oracle, we can achieve this easily.Design The mapping as shown in the above image.And Write the sql query in the source qualifier as follows,
Select
Emp.empno,
Emp.ename,
Emp.sal,
Lag(emp.sal,1) over(order by emp.sal) as prevsal
From
Emp
This will bring our desired output.