Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query

Author  Topic 

sumitarora
Starting Member

2 Posts

Posted - 2005-09-04 : 13:59:15
I want a query for the follwing ---->

The salaries in a table are
salary
======
1000
2000
3000
4000
5000

I want the output of the query as
salary
======
1000
3000
6000
10000
15000

nr
SQLTeam MVY

12543 Posts

Posted - 2005-09-04 : 15:40:10
select salary = (select sum(t2.salary) from tbl where t2.salary <= t1.salary)
from salary t1
order by t1.salary

It's better to give a descriptive title to questions if you want people to take an interest.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-05 : 00:43:54
Small correction on nr's query

select salary = (select sum(t2.salary) from tbl t2 where t2.salary <= t1.salary)
from salary t1
order by t1.salary


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -