MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 17th, 2003, 05:41 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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?

Reply With Quote
  #2  
Old July 17th, 2003, 07:40 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
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?

Reply With Quote
  #3  
Old July 17th, 2003, 10:32 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
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.

Reply With Quote
  #4  
Old July 17th, 2003, 11:23 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
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.

Reply With Quote
  #5  
Old July 18th, 2003, 03:07 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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...

Reply With Quote
  #6  
Old July 9th, 2007, 08:04 AM
bmn bmn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 29 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 41 m 51 sec
Reputation Power: 0
Lightbulb Answer...

Quote:
Originally Posted by avit
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.


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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySQL: Mean, Median, Mode (statistics)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT