LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-21-2012, 08:49 PM   #1
dray235
LQ Newbie
 
Registered: May 2012
Posts: 1

Rep: Reputation: Disabled
MySql last ten entries percentage


Hi,

I have a database that I need to extract the last ten entries from and to get a percentage of the how many times the most popular entry was picked from these ten entries.

This is currently getting me the most popular entry from the last 10 entries:

Code:
$sql =  "SELECT data, count( * ) AS Popularity FROM (SELECT data FROM table ORDER BY id DESC LIMIT 10) table GROUP BY data ORDER BY popularity DESC LIMIT 1";
What can I do to get the most popular as a percentage please?
 
Old 05-22-2012, 07:04 PM   #2
yancek
Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 5,066

Rep: Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803
I have a select statement in a php script which does something similar. It select the number of "wins" from a "matches" table from a database including league tennis results and prints them out in an echo statement as a percentage.

PHP Code:
$query"SELECT (SUM(if(W_L='w', 1,0)) / COUNT(*) * 100) FROM matches"
The above only has two options, w or l so the if probably won't work in your case and you will obviously need to use some trial and error to modify it. I found this online somewhere and modified it until it worked. Not being a programmer, I would not be able to explain why this works, but it does. Unfortunately, I haven't a clue about what specifically you could do to get it working in your case. Good luck!

Last edited by yancek; 05-22-2012 at 07:08 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Percentage of different MySQL server _versions_ in use Harry2o Linux - Software 2 02-03-2012 04:37 AM
I'm getting duplicata entries in mysql database countrydj Programming 7 04-14-2011 05:07 PM
[SOLVED] MySQL: Multiple entries unihiekka Linux - Newbie 2 04-05-2011 06:14 AM
Scripting entries into mysql with logic spiffytech Linux - Software 1 01-16-2006 03:55 AM
LXer: Ten BY TEN. India's IT & BPO Outsourcing. LXer Syndicated Linux News 0 12-26-2005 04:31 PM


All times are GMT -5. The time now is 05:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration