473,382 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Calculate the median

I really don't know how to calculate the median. Can anybody help me?
Nov 13 '05 #1
2 9110
hu**********@pi.be (Hugo L.) wrote in message news:<66**************************@posting.google. com>...
I really don't know how to calculate the median. Can anybody help me?


one way...
http://support.microsoft.com/default...81&Product=acc
Nov 13 '05 #2
"Hugo L." <hu**********@pi.be> wrote in message
news:66**************************@posting.google.c om...
I really don't know how to calculate the median. Can anybody help me?

If you want a "straight SQL" approach you could try something like this:

Let's say you have a table called dist:

create table dist
(
id counter not null primary key,
c int not null
)

The statistical median is found by:

select d1.c AS median
from dist AS d1, dist AS d2
group by d1.c
having
count(IIf(d2.c <= d1.c,1,null))=(count(*)+1)/2

The statistical median must be one of the values in the set. In this case,
if table dist has an odd number of rows, the median will be the middle
value. If the number is even, the query returns the lesser of the two middle
values.

A financial median does not have to be one of the values of the set. In the
case of an even number of values, it is the average of the two middle
values.

select IIf((count(*) Mod 2)=0,
(d1.c+min(IIf(d2.c>d1.c,d2.c,null))/2),d1.c)
as median
from dist as d1, dist as d2
group by d1.c
having
count(IIf(d2.c <= d1.c,1,null))=(count(*)+1)/2
Neither of these solutions will work properly if you have
duplicate values centered around the median. You can still handle that in
SQL but it is really complicated.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: uspensky | last post by:
I have a table (cars) with 3 fields: VIN, Class, sell_price 101, sports, 10000 102, sports, 11000 103, luxury, 9000 104, sports, 11000 105, sports, 11000 106, luxury, 5000 107, sports, 11000
0
by: Sebastien.LICHTHERTE | last post by:
Hello, I need to calculate the median and percentile of values in a group by query satisfying several criteria the user is asked to fill in when opening the query. A have a table called RX with...
3
by: Scott | last post by:
I need to take the median from a field of records in a report. Can someone shed the light how to do it. Thanks, Scott
7
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
73
by: brady | last post by:
I have a function called int calcMedian(int ar, int numElements) How do i code the function to calculate the median in the array? Please help
1
by: CrostonScottish | last post by:
Has anybody got any ideas or nifty code for calculating the median value in a form. I currently have a database which we use for post-course evaluations. Part of the evaluation asks the attendees...
3
by: mehwishobaid | last post by:
i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
2
by: dmorand | last post by:
Does anyone have any experience with retrieving a median value using SQL server? I'm trying to retrieve a median value from a list of various numerical values. Any help would be appreciated.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.