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

How to sort by specified algorithm in mysql

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:45
Original
1169 people have browsed it

<code>id(主键) agree  total
1        2     5
2        40    100   
3        3     30</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template