PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 25th, 2002, 12:36 PM
DSNLG DSNLG is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 11 DSNLG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 6 sec
Reputation 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?

Reply With Quote
  #2  
Old August 25th, 2002, 01:02 PM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 44 m 46 sec
Reputation Power: 25
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

Reply With Quote
  #3  
Old August 25th, 2002, 01:24 PM
DSNLG DSNLG is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 11 DSNLG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 6 sec
Reputation 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.

Reply With Quote
  #4  
Old August 25th, 2002, 03:36 PM
DSNLG DSNLG is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 11 DSNLG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 6 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Division in a MySQL query?

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap