Quality Testing

Quality is delighting customers

could any one help me to solve bellow QUERY.
i have emp table. it had eno sal

EMP TABLE
---------
Eno SAL
-- ---
1 100
2 200
3 300
4 400

i want to calculate esalas bellow

eno sal esal
--- -- ----
1 100 100
2 200 300
3 300 600
4 400 1000


i need a need a select query to check esal.

Views: 309

Reply to This

Replies to This Discussion

it seems to be a fibonacci series(esal)...u can write a pl/sql code for this...

Hi viswa,

this will give u a result,

Declare @res as int Declare @r as int Declare @i int Declare @c int
set @res=0 set @c=(select count(*) from emp) set @i=0
Create table #result (eno int,esal int)
While @i < @c Begin
Select @r=(@res + sal) from Emp where eno=(@i+1) order by eno desc
set @res=@r
Set @i = @i + 1
insert into #result values (@i,@r )
End
Select a.eno,a.sal,b.esal from emp a inner join #result b on a.eno=b.eno

Thank you very much Vinodh

Thanks Vinodh.

Most Welcome Guys.......:-)

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2022   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service