View previous topic :: View next topic |
Author |
Message |
schintala Beginner
Joined: 18 May 2005 Posts: 108 Topics: 31 Location: USA
|
Posted: Thu May 26, 2005 9:11 am Post subject: Query Optimization |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu May 26, 2005 9:20 am Post subject: |
|
|
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 |
|
 |
schintala Beginner
Joined: 18 May 2005 Posts: 108 Topics: 31 Location: USA
|
Posted: Thu May 26, 2005 9:36 am Post subject: |
|
|
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 |
|
 |
schintala Beginner
Joined: 18 May 2005 Posts: 108 Topics: 31 Location: USA
|
Posted: Thu May 26, 2005 9:40 am Post subject: |
|
|
I am sorry I meant for median not mean. I appologize for the confusion. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
schintala Beginner
Joined: 18 May 2005 Posts: 108 Topics: 31 Location: USA
|
Posted: Thu May 26, 2005 9:58 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu May 26, 2005 10:06 am Post subject: |
|
|
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 |
|
 |
schintala Beginner
Joined: 18 May 2005 Posts: 108 Topics: 31 Location: USA
|
Posted: Thu May 26, 2005 10:22 am Post subject: |
|
|
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 |
|
 |
|
|