Trying to sort by rating. It is necessary that the MySQL condition ORDER BY takes a field with estimates divided it into a field with the number of voters.
Is it possible to put such a condition? What would such a design look like?
Trying to sort by rating. It is necessary that the MySQL condition ORDER BY takes a field with estimates divided it into a field with the number of voters.
Is it possible to put such a condition? What would such a design look like?
To compose such a query, you can use expressions after the ORDER BY , for example
SELECT * FROM tbl ORDER BY marks / total DESC If the total field can take the value 0, then in order to avoid division by zero, you can add a conditional choice using the IF() function
SELECT * FROM tbl ORDER BY IF(total = 0, 0, marks / total) DESC Source: https://ru.stackoverflow.com/questions/481996/
All Articles