473,657 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Median of GROUP BY values

In

http://groups-beta.google.com/group/...b88fc3fd?hl=en

I said:

If qryRankForMedia n is changed to select only values within a group
(along with a suitable WHERE clause for WantRanking) it may be possible
to get the median of each group in its output line as well by using SQL
to reference the Groups value. To do that for the Median function
would require modification to accept the Groups value as an argument.
Of course the odds of someone needing this functionality are long. If
anyone needs that I'll try to flesh out the details.
I received an email from someone in Europe requesting that I provide
the details of how to do this. I wonder how many people are reading
this NG?

tblSample:
ID Value Groups
1 1 A
2 2 A
3 3 A
4 4 B
5 5 B
6 5 B
7 5 C
8 6 C

qryRankForMedia n:
SELECT tblSample.Value , (SELECT Count(A.ID) FROM tblSample AS A WHERE
A.Value < tblSample.Value AND A.Groups = tblSample.Group s)+(SELECT
Count(A.ID) FROM tblSample AS A WHERE A.Value = tblSample.Value AND
A.ID < tblSample.ID AND A.Groups = tblSample.Group s)+1 AS
RankingWithinGr oup, (SELECT Count(*) FROM tblSample AS A WHERE
A.Groups = tblSample.Group s)/2+0.5 AS WantRankingWith inGroup, Groups
FROM tblSample;

! qryRankForMedia n:
Value RankingWithinGr oup WantRankingWith inGroup Groups
1 1 2 A
2 2 2 A
3 3 2 A
4 1 2 B
5 2 2 B
5 3 2 B
5 1 1.5 C
6 2 1.5 C

qryGroupMedians :
SELECT Avg(Value) AS Median, qryRankForMedia n.Groups FROM
qryRankForMedia n WHERE (Abs([RankingWithinGr oup] -
[WantRankingWith inGroup]) < 0.6) GROUP BY qryRankForMedia n.Groups;

! qryGroupMedians :
Median Groups
2 A
5 B
5.5 C

These are the only values I tested so be sure to test thoroughly before
using this technique. I will be getting a new email address soon so in
the meantime please post any questions or comments to this NG.

James A. Fortune

Nov 13 '05 #1
0 2610

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

Similar topics

4
9707
by: Ross Contino | last post by:
Hello to all: I have been searching the web for examples on how to determine a median value in a mySQL table. I have reviewed the article at http://mysql.progen.com.tr/doc/en/Group_by_functions.html. I am an experienced VB programmer that has recently moved to PHP/mySQL. My employer has a text file outputted from a vendor specific software with data. However it cannot be manipulated because it is text. I created a web that reads the...
2
20171
by: michael way | last post by:
I read the follow query about calculating median posted by Daivd Porta on 10/8/03. CREATE TABLE SomeValues (keyx CHAR(1) PRIMARY KEY, valuex INTEGER NOT NULL) INSERT INTO SomeValues VALUES ('A',1) INSERT INTO SomeValues VALUES ('B',2) INSERT INTO SomeValues VALUES ('C',3) INSERT INTO SomeValues VALUES ('D',4)
2
9131
by: Hugo L. | last post by:
I really don't know how to calculate the median. Can anybody help me?
8
14099
by: nick.vitone | last post by:
Hi, I'm somewhat of a novice at Access, and I have no experience programming whatsoever. I'm attempting to calculate the statistical median in a query. I need to "Group by" one column and find the median of the another, though I'm not sure how. I've been able to add the "Median" function (from the Microsoft Access Help Archive), but I can't figure out how to incorporate that into the Totals. Do I need to use the "expression" and...
3
2943
by: gunnarnime | last post by:
Can I get the following function to work with Fieldnames that have spaces in it? I've tried spqaure brackets to no avail. Any help would be appreciated. Public Function DMedian(FieldName As String, _ TableName As String, _ Optional Criteria As Variant) As Double On Error GoTo Err_DMedian
2
12980
by: Drebin | last post by:
I'm looking for mean, median, mode and standard deviation - maybe a couple methods that take in an array of floats or something?? Thanks much!
4
8169
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
5
9417
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new query it without making a table out of query 1. I can't find a median function in the "Total" field, so is there so way to make an expression to calculate the median of the orignial data from query 1 in my new query? Also, what does name by...
0
1688
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 this kind of data : HOSP TYPE SUB DAP A THO F 1
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.