Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > How to show Med...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 11003 of 11517
Post > Topic >>

How to show Median in a GROUP BY clause? (AVE works, Median doesn'

by HumanJHawkins <JHawkins@[EMAIL PROTECTED] > Apr 25, 2008 at 11:58 AM

We are using SQL Server 2000. I have already learned that there is no
MEDIAN, or MODE function to go along with the AVE... I've also found
several methods of computing Median. The one I like best is:

-- Apologies for not citing the source... I lost the website and the
file I downloaded has no ID in it.
SELECT
((SELECT MAX(iNumericField) FROM
    (SELECT TOP 50 PERCENT iNumericField FROM dbo.MyTable ORDER BY
iNumericField) AS W1) +
 (SELECT MIN(iNumericField) FROM
    (SELECT TOP 50 PERCENT iNumericField FROM dbo.MyTable ORDER BY
iNumericField DESC) AS W2)
) /2 AS Median;
-- END

However, now I want to use this in a GROUP BY clause and I have no
idea how.

-- What can I replace the non-functioning Median(flData) part with?
SELECT     iBin, AVG(flData) AS Mean_Data, Median(flData) AS
Median_Data
FROM         dbo.MyData
GROUP BY iBin
-- END

Is there some syntax for embedding the above "Get the Median" code
into my GROUP BY query? Is there some syntax to turn it into a
function that so I can make my own "Median()" function?

Many thanks in advance!
 




 3 Posts in Topic:
How to show Median in a GROUP BY clause? (AVE works, Median does
HumanJHawkins <JHawkin  2008-04-25 11:58:56 
Re: How to show Median in a GROUP BY clause? (AVE works, Median
"Plamen Ratchev"  2008-04-25 20:21:02 
Re: How to show Median in a GROUP BY clause? (AVE works, Median
HumanJHawkins <JHawkin  2008-04-28 09:55:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 0:59:24 CST 2008.