IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SQL Query to get the 3rd max. salary from a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gvel19

New User


Joined: 20 Jul 2008
Posts: 19
Location: Schenactady, US

PostPosted: Mon Sep 29, 2008 12:13 pm
Reply with quote

Hi,

1) I need a SQL query to fetch the 3rd maximum salary from a table.
2) Also need to get the list of employees (From table A) whose salary is greater than the average salary of the employees from another table (table B).

Thanks,
Vel
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Mon Sep 29, 2008 1:10 pm
Reply with quote

Vel, this is a forum not a software factory, it would be good if you could post what you have tried so far.
Back to top
View user's profile Send private message
birdy K

New User


Joined: 05 Mar 2008
Posts: 72
Location: chennai

PostPosted: Mon Sep 29, 2008 1:18 pm
Reply with quote

To select the third max. You can try this.
Code:

  SELECT MAX(Sal) FROM tablename           
 WHERE Sal <(SELECT MAX(Sal) FROM  tablename
       WHERE Sal < (SELECT MAX(Sal) FROM tablename));
                           
Back to top
View user's profile Send private message
gvel19

New User


Joined: 20 Jul 2008
Posts: 19
Location: Schenactady, US

PostPosted: Mon Sep 29, 2008 1:37 pm
Reply with quote

Thanks a lot birdy.

Acevedo : I'm extremely sorry for that. I have tried but didn't get any hint for the query.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Mon Sep 29, 2008 2:07 pm
Reply with quote

a search for THIRD in the DB2 forum:

how to get third largest element in a table?

sql query, second or third top employee..

hth
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts RC query -Time column CA Products 3
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top