Weborum Webmaster Forum > Mathematical functions in MySQL
Help - Search - Members - Calendar
Full Version: Mathematical functions in MySQL
Weborum Webmaster Forum > Web Page Design > PHP
sjthomas
Hey guys, is there anyway to perform mathematical functions within a MySQL query. What I want to do is something like this:

CODE
SELECT * FROM table ORDER BY (number1 / number2) DESC LIMIT 0,10


I think you can probably guess what I'm trying to do, tis a voting script and I have the total of all the votes plus the number of the votes and I want to order by the average vote amount, if you get me. I've already got a value for the total (average) vote int he DB but its only to one decimal place and thus not practical for ordering (i.e there could be lots of sites that scor 9.1 for example).

Anyone got any ideas? Can this be done?
aviansuicide
http://dev.mysql.com/doc/mysql/en/numeric-functions.html

but what you want is AVG()..which is an agregate function:

http://dev.mysql.com/doc/mysql/en/group-by-functions.html
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.