Home > Article > Backend Development > How to sort by specified algorithm in mysql
<code>id(主键) agree total 1 2 5 2 40 100 3 3 30</code>
Suppose the content of my data table is as above
I want to sort it according to the accuracy rate. The algorithm is (agree/total)
Then sort it from high to bottom according to the accuracy rate
Can it be achieved? If not, is there any alternative?
<code>id(主键) agree total 1 2 5 2 40 100 3 3 30</code>
Suppose the content of my data table is as above
I want to sort it according to the accuracy rate. The algorithm is (agree/total)
Then sort it from high to bottom according to the accuracy rate
Can it be achieved? If not, is there any alternative?
<code class="mysql"> SELECT * FROM xxxxxx ORDER BY agree/total DESC</code>
You can consider adding a field, or caching the last calculated value, etc.
Don’t use the database to do this kind of thing, the database is very busy. Just let PHP protect the front end and don't put pressure on the database. Once the number of concurrency increases, it may crash at any time.