Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Try out this query-Please---Cummulative salary

Status
Not open for further replies.

UDIT

Technical User
Nov 24, 2000
37
US
hi there,
i ve been trying to figure out how to solve this query but havent found any success as yet , could anyone help:

ques : To write down a query to calculate the cullulative sal of an employee i.e along with the employeeid,employee name,sal,CUMMULATIVE SAL --column should also come as output(Computed column of course)
empid ename sal c_sal
eg: aa1122 bobby 2000 2000
asd344 celina 5000 7000 --(5000+2000)
234f5r jack 6000 13000 (7000+6000)

etc........

thanks.
 
If you know you have a column you are sorting by,
which I would assume you would in this scenario,
than you could do it thusly:

SELECT empid,
ename,
sal,
(SELECT sum(sal)
FROM yourTable
WHERE empid <= t.empid) c_sal
FROM yourTable t
ORDER BY empid

I'd bet there are other ways.

Have fun,

Bob
 
Hi :)

I tried ur query n its flawless :) but unfortunately I m looking exactly the opposite of it. My problem is something like that.

ID Name DOB
1 A 1/1/01
2 B 2/2/01
3 C 3/2/01
4 D 4/4/01

The query I want to write will give an output like

ID Name DOB NumberLeft
1 A 1/1/01 4-1=3
2 B 2/2/01 4-2=2 or 3-1=2
3 C 3/2/01 4-3=1
4 D 4/4/01 4-4=0

Is there anyway that I could work myself backward?

Cheers!
Aqif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top