Preface In our daily development process, sorting is often used, and sometimes there is such a demand. For example, you need to sort the query results according to the specific value of a field. As in the following example The above is a personal information table. Suppose we want to sort it by 'seiki', 'iris', 'xut'. That is, name='seiki','iris','xut' are used for sorting. What should we do when we encounter such a requirement? In fact, there is a MySQL function that can handle this requirement very conveniently. That is the field() function How to use it: Among them, Meaning: The field str returns the queried result set in the order of strings str1, str2, str3, str4. If the str field value in the table does not exist in the record of str1, str2, str3, str4, it will be returned at the front of the result set. Now that we know how to use it, let's implement the above requirements. First, let’s sort in positive order Or sort by 'seiki', 'iris', the results are as follows Now let's sort 'seiki', 'iris' in reverse order You can see that iris is at the front. Why is that? See the annotation on the picture above! Well, this function is still very useful Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Programs to query port usage and clear port usage in Windows operating system
>>: Angular Dependency Injection Explained
<br />Just like an article, our web pages sh...
This article example shares the specific code of ...
<br />I'm basically going crazy with thi...
1. I purchased a VPS and CentOS system, and found...
When looking at High Performance MySQL Version 3 ...
Table of contents Write docker-compose.yml Run do...
Table of contents 1. Create components using func...
XHTML defines three document type declarations. T...
Conversion between rgba and filter values under...
Currently, almost all large websites and applicat...
Table of contents Preface 1. Parent component pas...
1. First of all, we need to distinguish between t...
1.This points to 1. Who calls whom? example: func...
Password Mode PDO::__construct(): The server requ...
As we all know, SSH is currently the most reliabl...