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
 
Print first 5 max salary using SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
raviprasath_kp
Warnings : 1

New User


Joined: 20 Feb 2005
Posts: 65
Location: chennai

PostPosted: Wed Jun 06, 2007 8:26 pm    Post subject: Print first 5 max salary using SQL
Reply with quote

Hi i have one db2 table

i want to print first 5 max salary

any one can suggest some qurey for that
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 06, 2007 9:13 pm    Post subject: Re: max salary qurey
Reply with quote

raviprasath_kp wrote:
Hi i have one db2 table

i want to print first 5 max salary

any one can suggest some qurey for that


Here it is. Expect terrible response time. icon_cry.gif
Code:
SELECT MAX(SALARY) FROM SALARYS                           
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS) 
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS))
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS)))
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS))))
ORDER BY 1 DESC;
Back to top
View user's profile Send private message
Abirami.YN

New User


Joined: 16 Jul 2005
Posts: 15
Location: India - Chennai

PostPosted: Thu Jun 07, 2007 1:09 pm    Post subject: Re: Print first 5 max salary using SQL
Reply with quote

Hi,

Try this query to fetch first 5 maximum salary amount

SELECT SALARY FROM SALTABLE
ORDER BY SALARY DESC
FETCH FIRST 5 ROWS ONLY


Regards
Abirami
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 print out the correct info in LOOP? jackzhang75 CLIST & REXX 7 Wed Dec 23, 2015 10:39 pm
No new posts How to print a variable in SAS progra... LOKESH DAIVAM All Other Mainframe Topics 6 Thu Aug 13, 2015 12:24 pm
No new posts How to print out only array member wi... jackzhang75 CLIST & REXX 13 Wed Jun 18, 2014 7:15 pm
No new posts RMDS - Print table using DBNMALST Mark Kerner IBM Tools 2 Thu May 15, 2014 8:38 pm
No new posts Print blanks for unchanged control fi... David Sde DFSORT/ICETOOL 6 Mon Jan 27, 2014 5:31 am

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