Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us