| Author |
Topic |
|
ruchita
Starting Member
5 Posts |
Posted - 2007-07-18 : 00:53:42
|
| suppose i want to find top three salaried people i can find top 3 salary using max salary but i have a problem i want to find Second Highest Salary suppose top 3 salaries are 10$ , 5$ and 2$ i want to find only 5$ ]can anyone help me with aquery for this |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-18 : 00:57:19
|
just search for it in this forum KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-07-18 : 01:15:24
|
quote: Originally posted by khtan just search for it in this forum KH[spoiler]Time is always against us[/spoiler]
you can start with the sticky in "New to SQL Server" section.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
ruchita
Starting Member
5 Posts |
Posted - 2007-07-18 : 01:18:35
|
| thanks for the replies my syntax select empid,max(salary)from employeeswhere salary>any(select max(salary)from employeeswhere rownum<=2)is this right ?..experst plz let me know RegdsRuchita |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-18 : 01:49:11
|
quote: Originally posted by ruchita thanks for the replies my syntax select empid,max(salary)from employeeswhere salary>any(select max(salary)from employeeswhere rownum<=2)is this right ?..experst plz let me know RegdsRuchita
Have you tried to run it ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ruchita
Starting Member
5 Posts |
Posted - 2007-07-18 : 02:20:44
|
| doesn't give the right answer ....select max(sal) from employees where sal> any (select max(sal) from employees where Rownum()<=2 orderby sal desc )can u plz help me out wats wrong ? is the syntax wrong ?am new to sql server tried searching as per ur suggesttion but cudnt find the reqd topic regards |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-18 : 02:34:20
|
| Select min(sal) as sal from(select top 2 sal from table order by sal DESC) TMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-18 : 05:21:00
|
| SELECT MAX(Sal) FROM Table WHERE Sal < (SELECT MAX(Sal) FROM Table)Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-18 : 07:25:06
|
quote: Originally posted by Peso SELECT MAX(Sal) FROM Table WHERE Sal < (SELECT MAX(Sal) FROM Table)Peter LarssonHelsingborg, Sweden
I prefer the solution I have given that can work work any N value MadhivananFailing to plan is Planning to fail |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-07-18 : 11:12:52
|
| Standard job interview question #1.Don't interviewers ever come up with anything original?CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-19 : 04:19:51
|
quote: Originally posted by Michael Valentine Jones Standard job interview question #1.Don't interviewers ever come up with anything original?CODO ERGO SUM
I dont know why they always target second highest paid employee MadhivananFailing to plan is Planning to fail |
 |
|
|
|