August 25th, 2002, 12:36 PM
Division in a MySQL query?
I have two rating fields in my table. rate_total holds the total sum of all submitted ratings and rate_count holds the number of times this row has been rated.
so if one person submits a rating of 4, rate_total = 4 and rate_count = 1
if someone esle submits a rating of 3, rate_total = 7 and rate_count = 2
is it possible to divide rate_total by rate_count in my SELECT query and return the row with the highest result? or do i need to create a third field, rate_result, and update that with the quotient everytime someone submits a rating?
August 25th, 2002, 01:02 PM
Why don't you just try it? (Hint: it is possible...)
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep
August 25th, 2002, 01:24 PM
I checked the MySQL docs and saw that it was possible but they didn't give any usage examples (besides "SELECT 3/5 => 0.6" ). I tried experimenting for about a half an hour before posting my original message. Oh well. The latter solution works and is more convenient for me. Thanks for your response.
August 25th, 2002, 03:36 PM
Damn, is it as easy as "SELECT (rate_total/rate_count) as 'rate_result'"? And I've already changed my tables and functions...sigh.