|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
MySQL: Mean, Median, Mode (statistics)
it's actually the "mode" that i'm looking to return... I decided to put all three arithmetic statistical terms in the topic so people don't mis-interpret my use of the word "mode"
mode is the number that appears most in a sequence of numbers... So i have a column in my table that holds foreign keys to another table... what i want is to find which partical key appears most in that field... [ideally i'd like to find the top five, but let's not complicate things yet] an example of my table: ID FK 01 00 02 02 03 02 04 01 05 03 the mean of field FK is 02... does anyone know if its possible to determine this in a select statement? |
|
#2
|
|||
|
|||
|
Code:
SELECT fk as key, count(fk) AS qty FROM mytable GROUP BY key ORDER BY qty DESC LIMIT 1; (I think that's right...) Result columns: key will tell you which one, qty will tell you how many. Select only one or the other according to what you need. I might have got your terminology mixed up, but those are the results you need, aren't they? |
|
#3
|
|||
|
|||
|
avit seems to have given you the correct solution to your first problem (mode)... for the mean you just use the AVG function.
SELECT AVG(FK) as mean FROM...
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#4
|
|||
|
|||
|
Hmm, close enough for me (a non-statistician) but technically I don't think AVG == MEAN.
AVG is to add up all values and divide by the number of records. MEDIAN is (MIN + MAX) / 2 MEAN is to select the middle value in a series. Or is it the other way around... care you enlighten us, MadCow? Oh by the way... it's probably obvious but you can change LIMIT to 5 if that's the actual result you wanted in your original post. Cheers. Last edited by avit : July 18th, 2003 at 12:12 AM. |
|
#5
|
||||
|
||||
|
Thank you avit for all your help...
That worked perfect.. I was going nuts trying to figure out the logic, but now that I can read it, it completely makes sense... |
|
#6
|
|||
|
|||
|
Quote:
Me, a statistician (using a BugMeNot account since registration is a horror): Sometimes AVG == MEAN MEAN is all values added and divided by number of records. AVG() in MySQL is the same. AVERAGE in a mathematical sense can be either of MEAN, MEDIAN and MODE. MEDIAN is the middle value. MODE is the most common. There you go... - gratemyl |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > MySQL: Mean, Median, Mode (statistics) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|