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 select n max value from column

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

New User


Joined: 24 Nov 2004
Posts: 20
Location: chennai

PostPosted: Thu Nov 25, 2004 10:27 am    Post subject: how to select n max value from column
Reply with quote

[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.


veerababu.
Back to top
View user's profile Send private message

jz1b0c

Active User


Joined: 25 Jan 2004
Posts: 160
Location: Toronto, Canada

PostPosted: Thu Nov 25, 2004 10:36 pm    Post subject: Re: how to select n max value from column
Reply with quote

veera wrote:
[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.


veerababu.


VEERA, HERE IS THE ANSWER


SELECT "LOAN_NUM"
FROM TEST.LOAN
ORDER BY LOAN_NUM ASC
FETCH FIRST 4 ROWS ONLY ;

IF YOU ARE USING THIS IN A DB2 PROGRAM
USE OPTIMIZE CLAUSE IN DECLARE STATEMENT.
Back to top
View user's profile Send private message
ksivapradeep

New User


Joined: 30 Jul 2004
Posts: 95

PostPosted: Fri Nov 26, 2004 7:19 pm    Post subject: Re: how to select n max value from column
Reply with quote

hi jz1b0c,

veera asked the first height rows not the first n rows how to write that.ur query is correct but thats only to fetch first n rows.

regards,
siva pradeep
Back to top
View user's profile Send private message
jz1b0c

Active User


Joined: 25 Jan 2004
Posts: 160
Location: Toronto, Canada

PostPosted: Sat Nov 27, 2004 3:13 am    Post subject: Re: how to select n max value from column
Reply with quote

veera wrote:
[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.


veerababu.


" first n max values " This confused me. It should have been nth max value in a table.
Back to top
View user's profile Send private message
jz1b0c

Active User


Joined: 25 Jan 2004
Posts: 160
Location: Toronto, Canada

PostPosted: Sat Nov 27, 2004 3:48 am    Post subject:
Reply with quote

Veera,

Try this.

SELECT *
FROM TEST.TABLE1 T1
WHERE 5 = ( SELECT COUNT(DISTINCT T2.NUM)
FROM TEST.TABLE2 T2
WHERE T2.NUM >= T1.NUM)
ORDER BY NUM DESC ;;


tHIS WILL GIVE 5TH MAX
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 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
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm

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