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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Re:Sql Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-11-08 : 08:18:27
Rajib Mandal writes "I am facing some typical problem.
I have a table
Emp

EmpId Salary
1 1000
2 2000
3 3000
4 4000
5 5000
6 6000

I want a output that returns a result for each empId the no of
persons who earns more salary
means
EmpId No persons
1 5
2 4
3 3"

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-08 : 08:29:03
select empid, (select count(*) from emp t2 where t2.salary > t1.salary)
from emp t1


==========================================
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
   

- Advertisement -