MySQL Forums
Forum List  »  Newbie

Re: Dividing two columns in mysql
Posted by: Stefan Hinz
Date: March 07, 2014 09:36AM

For accuracy, you should get 36.00, not 36.43, as can be seen in this simplified example:

mysql> SELECT ROUND(SUM(51/(51+90)),2)*100;
+------------------------------+
| ROUND(SUM(51/(51+90)),2)*100 |
+------------------------------+
| 36.00 |
+------------------------------+
1 row in set (0.00 sec)

To debug, why not output GOALS and BEHINDS? I suspect your problem lies there. So, change the first line of your statement to this ...

SELECT Team, GOALS, BEHINDS, ROUND(SUM(GOALS/(GOALS+BEHINDS)),2)*100 AS ACCURACY

... and see what you get.

Stefan Hinz, MySQL Documentation, Berlin, Germany

Options: ReplyQuote


Subject
Written By
Posted
March 07, 2014 07:58AM
Re: Dividing two columns in mysql
March 07, 2014 09:36AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.