Solved

SQL 2005

Posted on 2012-03-13
3
201 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

12 Experts available now in Live!

Get 1:1 Help Now