View previous topic :: View next topic
|
Author |
Message |
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi All
I have a employee table with a salary field. How to calculate the second maximum salary in the employee table. Please provide the query. |
|
Back to top |
|
|
sridevi2005
New User
Joined: 15 Sep 2005 Posts: 42
|
|
|
|
Hi,
Try the following query.
Select min(salary) from employee
where salary > select salary from employee
where salary > avg(sal).
Please let me know if u have any query.
Thanks,
Sridevi |
|
Back to top |
|
|
mathiprakash
New User
Joined: 29 Apr 2005 Posts: 14 Location: Pune, India.
|
|
Back to top |
|
|
radhakrishnan82
Active User
Joined: 31 Mar 2005 Posts: 435 Location: chennai, India
|
|
|
|
try this code:
Code: |
SELECT DISTINCT (SALARY)
FROM EMPTABLE A
WHERE 2 =
(SELECT COUNT (DISTINCT (B.SALARY))
FROM EMPTABLE B
WHERE A.SALARY <= B.SALARY); |
Try the following to find the 'n'th max salary of the table:
Quote:
Code: |
SELECT EMPSAL FROM EMPTABLE X
WHERE (n-1) IN
(SELECT COUNT(*) FROM EMPTABLE Y
WHERE X.EMPSAL > Y.EMPSAL) |
Hope this helps. |
|
Back to top |
|
|
Kotes
New User
Joined: 03 May 2005 Posts: 5
|
|
|
|
Hi Iknow,
What radhakrishnan wrote is sucessfully works. |
|
Back to top |
|
|
jeyakanthan
New User
Joined: 18 May 2005 Posts: 12 Location: chennai
|
|
|
|
this is simple query
select max(salary) from emp-table where salary NOT IN
(select max(salary) from emp-table) |
|
Back to top |
|
|
nijugopalan
New User
Joined: 15 Oct 2005 Posts: 15 Location: pune
|
|
|
|
select max sal from emp where sal<(select max sal from emp)
is this correct |
|
Back to top |
|
|
|