Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: SQL Query to get the 3rd max. salary from a table
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    Post subject:
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    Post subject:
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    Post subject: Reply to: SQL Query to get the 3rd max. salary from a table
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us