We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL MEDIAN for Age Ranges

JCTDD
JCTDD asked
on
Medium Priority
514 Views
Last Modified: 2012-05-11
using sql server 2000

I am wondering how to calculate the Median from a table (Table1) that is grouped by Age ranges:

e.g.

Table1
Value    Age

100      16
100      16
50        20
300      17
200      22
150      23
250      24

What would be the code to display the MEDIAN like this:
Age Range   MEDIAN
< 21             200
21 < 25         225


NOTE:
< 21 means less than age of 21
21 < 25 means greater than equal to 21 but less than 25
Comment
Watch Question

Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
WHERE RowNum IN((Count + 1) / 2, (Count + 2) / 2)

Author

Commented:
thanks I will try them out
(I did find a few examples on the net but thought there might be another way)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.