Link to home
Start Free TrialLog in
Avatar of JCTDD
JCTDD

asked on

SQL MEDIAN for Age Ranges

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
ASKER CERTIFIED SOLUTION
Avatar of AmmarR
AmmarR
Flag of Bahrain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WHERE RowNum IN((Count + 1) / 2, (Count + 2) / 2)
Avatar of JCTDD
JCTDD

ASKER

thanks I will try them out
(I did find a few examples on the net but thought there might be another way)