Solved

Median for SQL 2000

Posted on 2006-10-30
9
914 Views
Last Modified: 2012-06-21
Just wondering if there was already a Median function in SQL 2000 that will perform the median by finding the middle number in a column with both even and odd numbers. I've already written a seperate select statement, but was wondering if there were a simpler way. I would also need the Median function to make sure the values in the column were numeric as some of them are 'NA' or 'N/A'-

I've been checking both EE and Googling for answers and their doesn't seem to  be anything consistent- I could be wrong


Thanks
0
Comment
Question by:friskee
  • 5
9 Comments
 
LVL 10

Expert Comment

by:AaronAbend
ID: 17836970
No there is no median function in SQL Server... (I just answered a question to show the code for computing a median on EE about 2 weeks ago)
0
 

Author Comment

by:friskee
ID: 17842660
aaron could you provide a link thnx
0
 

Author Comment

by:friskee
ID: 17867121
I've found a solution thnx
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:friskee
ID: 17905859
AaronAbend, if you will provide me the link to where this question was answered then I'll award you the points for responding to this question
0
 

Author Comment

by:friskee
ID: 18020750
Page monitor, please advise me on how to handle the points for this question- thnx
0
 

Author Comment

by:friskee
ID: 18189761
As the page editor suggested, I'm posting the median solution that  I am using:

Here's the median statement I'm using, it also includes Quartiles and an average, but nonetheless..

SELECT '1. Promptness' AS Quality,
     (
     SELECT AVG(
          CASE
               WHEN prac_promptness NOT IN ('N/A', 'NA')
               THEN Convert(integer,prac_promptness)
               ELSE NULL
          END
          )
     FROM dbo.TBL_EDTL_PRACEVAL
     WHERE prac_term = 'Fall Semester 2006'
     ) [Average Score],

     (
     SELECT SUM(promptness) / COUNT(promptness)
     FROM (
          SELECT TOP 25 PERCENT
               Convert(integer, prac_promptness )as promptness
          FROM dbo.TBL_EDTL_PRACEVAL
          WHERE prac_term = 'Fall Semester 2006'
               AND prac_promptness not in ( 'N/A','NA')
          ORDER BY Convert(integer, prac_promptness)
          ) AS X
     ) AS Quartile1,

     (
     SELECT SUM(promptness)/COUNT(promptness)
     FROM (
          SELECT TOP 25 PERCENT promptness
          FROM (
               SELECT TOP 50 PERCENT Convert(integer, prac_promptness )as promptness
               FROM dbo.TBL_EDTL_PRACEVAL
               WHERE prac_term = 'Fall Semester 2006'
                    AND prac_promptness not in ( 'N/A','NA')
               ORDER by Convert(integer, prac_promptness) DESC
               ) Src
          ORDER BY promptness
          ) tt
     ) AS Quartile3,

     (SELECT
          (SELECT TOP 1 Convert(integer, prac_promptness)
          FROM (
               SELECT TOP 50 PERCENT prac_promptness
               FROM dbo.TBL_EDTL_PRACEVAL
               WHERE prac_promptness NOT IN ( 'N/A','NA')
               ORDER BY Convert(integer, prac_promptness)
               ) s1
          ) +
          (SELECT TOP 1 Convert(integer, prac_promptness)
          FROM (
               SELECT TOP 50 PERCENT prac_promptness
               FROM dbo.TBL_EDTL_PRACEVAL
               WHERE prac_promptness NOT IN ( 'N/A','NA')
               ORDER BY Convert(integer, prac_promptness) DESC
               ) s2
          )
      / 2.0) AS Median

 
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18200041
PAQed with points refunded (150)

Computer101
EE Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Download ms sql express. 2 28
SQL, add where clause 5 24
TSQL XML Namespaces 7 24
RAISERROR WITH NOWAIT 2 18
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

821 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