How to sum and split MySql

Ok, so I have a user table and you want to get the maximum value for the user with the highest points divided by the score. Below is a rough idea of ​​what I'm looking for:

SELECT MAX(SUM(points)/SUM(score)) FROM users 

I am not interested in folding both columns and dividing, but I am interested in dividing points and points for each user and getting the highest value from the game.

+7
source share
2 answers

Perhaps you could do this with a subquery:

 Select max(points_over_Score) from (Select points/score AS points_over_score from users); 

And as thesunneversets mentioned in the comment could possibly be shortened to

 SELECT MAX(points/score) FROM users; 

You write a description of what you are trying to do, does not make it clear why your example has SUM , so I did not use it.

In addition, questions like this one are more suitable for stackoverflow.com . You can specify your own question to ask the moderator to reschedule it.

+3
source

Waiver of Disappointment WithFormsDesigner will not work if you need to sum all points, then all points, and then divide them. This answer divides each point into a score, then returns the highest answer.

This should work:

 SELECT MAX(sum_points / sum_score) from (SELECT SUM(points) as sum_points, SUM(score) as sum_score FROM users) 

By the way, this returns an "unusual" percentage. You probably want to split points by points. For example, if you get 70 out of 100, that is 70%, or the result (70) / points (100).

0
source

All Articles