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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
WHERE RowNum IN((Count + 1) / 2, (Count + 2) / 2)
ASKER
thanks I will try them out
(I did find a few examples on the net but thought there might be another way)
(I did find a few examples on the net but thought there might be another way)