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
 
How to query second maximum rows and 5th max row

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Thu Jan 04, 2007 10:10 pm    Post subject: How to query second maximum rows and 5th max row
Reply with quote

hai all
i have doubt
i want to query
find a second max row and 5th max row
how we write a query
by
raj
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Jan 04, 2007 10:49 pm    Post subject:
Reply with quote

Hello,

Please post some sample data and what you need the output to be.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Thu Jan 04, 2007 10:52 pm    Post subject:
Reply with quote

just take one table
it contain so many records
filed is empname, salary, dept
i want who is second highest salary person
and another who is 5 th highest salary person
by
raj
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 6:49 am    Post subject: Re: how to query second maximum rows and 5th max row
Reply with quote

I bet this one is going to top the list of popularity amongst regular questions being asked.

Take a look here... Previously Discussed...

Also it might help others if you use SEARCH facility before posting your questions.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Fri Jan 05, 2007 9:39 am    Post subject:
Reply with quote

Code:
SELECT MAX(SALARY) FROM EMP_TABLE A WHERE 5=(SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY<=B.SALARY);


For Nth Maximum Value:-
Code:
SELECT SALARY FROM EMP_TABLE A WHERE (N-1) IN (SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY < B. SALARY);


i have one table only not two tables
i have little bit confuse here how it comes table
B

my query is only one table not from two tables
i want to reterive the data from one table A only

by
raj
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 1:59 pm    Post subject: Re: how to query second maximum rows and 5th max row
Reply with quote

Raj,
Quote:
my query is only one table not from two tables
i want to reterive the data from one table A only

Did you execute the query or NOT?

Its not two tables... Its just kind of image of a single table... I would not go in further details of ALIAs, which is what this called...
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 -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm

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