?
Solved

SQL MEDIAN for Age Ranges

Posted on 2011-04-27
3
Medium Priority
?
495 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
0
Comment
Question by:JCTDD
3 Comments
 
LVL 15

Accepted Solution

by:
AmmarR earned 2000 total points
ID: 35481085
0
 
LVL 9

Expert Comment

by:radcaesar
ID: 35483169
WHERE RowNum IN((Count + 1) / 2, (Count + 2) / 2)
0
 

Author Comment

by:JCTDD
ID: 35487902
thanks I will try them out
(I did find a few examples on the net but thought there might be another way)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

864 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