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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


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