Home  >  Article  >  Backend Development  >  How to sort by specified algorithm in mysql

How to sort by specified algorithm in mysql

WBOY
WBOYOriginal
2016-08-04 09:19:451133browse

<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?

Reply content:

<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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn