SQL MEDIAN for Age Ranges

Posted on 2011-04-27
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:


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

< 21 means less than age of 21
21 < 25 means greater than equal to 21 but less than 25
Question by:JCTDD
    LVL 15

    Accepted Solution

    LVL 9

    Expert Comment

    WHERE RowNum IN((Count + 1) / 2, (Count + 2) / 2)

    Author Comment

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

    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

    Suggested Solutions

    There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
    I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    732 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

    17 Experts available now in Live!

    Get 1:1 Help Now