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
Write a SQL first SELECT DISTINCT from_id FROM co...
1. What is a transaction? A database transaction ...
String extraction without delimiters Question Req...
Preface When we write code, we occasionally encou...
Ubuntu 20.04 does not have root login enabled by ...
The mysql explain command is used to show how MyS...
First, install openssh-server in docker. After th...
Table of contents 1. Problematic SQL statements S...
1. Delete the original mariadb, otherwise mysql c...
First, let's introduce a few key points about...
1. Basic grammar Copy code The code is as follows...
nohup Command When using Unix/Linux, we usually w...
Table of contents 1. Follow the wizard to create ...
Without further ado, here is a demo picture. The ...
I won't say much nonsense, let's just loo...