IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

MAX function is taking more cpu time


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vicky10001
Warnings : 1

Active User


Joined: 13 Jul 2005
Posts: 136

PostPosted: Tue Aug 05, 2014 10:36 pm
Reply with quote

SELECT OAORNO
FROM tablename
WHERE
OAFACI = 812 AND
OAORNO = (SELECT MAX(OAORNO)
FROM tableName
WHERE OAFACI = 812)

The above query was taking more cpu time. We have defined index for the "OAFACI" & "OAORNO" columns. Let me know if you have any idea to reduce the cpu time.
Back to top
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10697
Location: italy

PostPosted: Wed Aug 06, 2014 5:58 pm
Reply with quote

Quote:
was taking more cpu time.


more as compared to what ???
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2508
Location: NY,USA

PostPosted: Thu Aug 07, 2014 12:51 am
Reply with quote

Try this, but you need to let us know the volume of data in underlying table and also what is the cpu time you are talking about?
Code:
SELECT OAORNO
FROM tablename
WHERE
OAFACI = 812
order by OAORNO desc
fetch first row only
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Thu Aug 07, 2014 12:52 pm
Reply with quote

What if you execute only subquery as below?
you didn't get desired result or that also taking more time?

Code:
SELECT MAX(OAORNO)
FROM tableName
WHERE OAFACI = 812


Why you need subquery in where clause if you interested in max value of OAORNO?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts DB2 - row_number function - Need 1st ... DB2 5
No new posts How to process dependent file based o... JCL & VSAM 8
No new posts reffering the filename with date and ... JCL & VSAM 9
No new posts How to Assign a Function key to Mainf... TSO/ISPF 4
No new posts Rexx STRIP Equivalent function in CLIST CLIST & REXX 5

Back to Top