Solved

SQL 2005

Posted on 2012-03-13
3
202 Views
Last Modified: 2012-03-15
Does SQL 2005 have the ability to calculate a Median?
0
Comment
Question by:dastaub
3 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 250 total points
ID: 37718618
There is no inbuilt function for that
Take a look at this article. It may point you to the correct direction
http://www.sqlmag.com/article/tsql3/calculating-the-median-gets-simpler-in-sql-server-2005
0
 
LVL 9

Assisted Solution

by:keyu
keyu earned 250 total points
ID: 37718626
DECLARE @groupID int; SET @groupID = 1
DECLARE @M1 int, @M2 int

SELECT TOP 50 PERCENT @M1 = numValue FROM sampleData WHERE groupID = @groupID ORDER BY numValue ASC
SELECT TOP 50 PERCENT @M2 = numValue FROM sampleData WHERE groupID = @groupID ORDER BY numValue DESC

SELECT (@M1+@M2)/2.0

REF. Link:  http://www.tek-tips.com/faqs.cfm?fid=6220
0
 

Author Closing Comment

by:dastaub
ID: 37727401
the second solution is what I currently do, but it does create a speed issue when dealing with larger tables and many medians needed.
The first solution was understandable because I just completed a course dealing with the features used in the solution.
Thank you to both.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now