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
Table of contents Various ways to merge objects (...
Here are some problems encountered in the use of ...
Table of contents Variable Scope The concept of c...
Table of contents Preface Parsing parameters Modi...
The specific code for encapsulating the image cap...
Table of contents 1 What is array flattening? 2 A...
First, understand the updatexml() function UPDATE...
Install the required environment 1. gcc installat...
In the front-end and back-end separation developm...
Let's first talk about the value of web front...
Due to the initial partitioning of the system, th...
Table of contents Oracle Isolation Levels MySQL I...
A few days ago, when I was working on a requireme...
Table of contents The dynamic particle effects ar...
When we use TypeScript, we want to use the type s...