#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    11
    Rep Power
    0

    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?
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    Why don't you just try it? (Hint: it is possible...)

    //NoXcuz
    UN*X is sexy!
    who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    11
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    11
    Rep Power
    0
    Damn, is it as easy as "SELECT (rate_total/rate_count) as 'rate_result'"? And I've already changed my tables and functions...sigh.

IMN logo majestic logo threadwatch logo seochat tools logo