MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query Optimization

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu May 26, 2005 9:11 am    Post subject: Query Optimization Reply with quote

Is there any better way of writing the below query to calculate the mean value from a table. It takes lot of time. When we impement it it will have lot of issues with huge volume of data. Any ideas please?

Code:

SELECT X.AGE  FROM IDTOUT01.ITOUADMN X, IDTOUT01.ITOUADMN Y             
 GROUP BY X.AGE HAVING((COUNT(*)-(SUM(SIGN(1-SIGN(Y.AGE-X.AGE))))) <=   
   FLOOR((COUNT(*)+1)/2)) AND                                           
  ((COUNT(*)-(SUM(SIGN(1+SIGN(Y.AGE-X.AGE))))) <=                       
   FLOOR((COUNT(*)+1)/2)) ;
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu May 26, 2005 9:20 am    Post subject: Reply with quote

Quote:

Is there any better way of writing the below query to calculate the mean value from a table.


Unless I totally forgot elementary stastics, Mean is nothing but an AVERAGE.

Why not use column function AVG ?

Code:


SELECT AVG(COLUMN)
  FROM TABLE
;


Hope this helps...

cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu May 26, 2005 9:36 am    Post subject: Reply with quote

Mean is different from AVG. For e.g let us say if you have set of two rows below.

Table1
COL1
1
2
3
4
5
6

Mean Here: Average of 3 and 4. Then it is 3.5.

Table2
1
2
3
4
5

Mean Here: Middle number which is 3 here in this case.
In otherwords if you have odd count mean would be middle of the numbers. Where as for even count it would be average of middle two numbers.
Hope you got it what I am looking for.
Back to top
View user's profile Send private message
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu May 26, 2005 9:40 am    Post subject: Reply with quote

I am sorry I meant for median not mean. I appologize for the confusion.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu May 26, 2005 9:47 am    Post subject: Reply with quote

Quote:

I am sorry I meant for median not mean. I appologize for the confusion.


schintala,

Did you get a chance to look at this topic?

http://www.mvsforums.com/helpboards/viewtopic.php?t=4068&highlight=median

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu May 26, 2005 9:58 am    Post subject: Reply with quote

Thank you Kolusu. I have gone thru similar approach but it requires creation of temprary table in our case. We avoided it and came out with this query. But this query is not worth in executing on large volume of data. We are looking options of optimizing it. If won't work out we'll have to consider the temporary table.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu May 26, 2005 10:06 am    Post subject: Reply with quote

Quote:

I have gone thru similar approach but it requires creation of temprary table in our case.


Why would need a temporary table?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu May 26, 2005 10:22 am    Post subject: Reply with quote

Because we are executing the query in two steps to avoid maximum time limit in obtaing the final result. We store the counts in temporary table and the result of median is calculated from the temp table.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group