This is the fourth day of my participation in Gwen Challenge


Mysql > limit pagination

Grammar:

Select * from (select * from (select * from (select * from)) limit m,n;

1) Limit does not require and or where.

2) M represents the starting data position, that is, the query starts from the data in article M

3) N indicates that the page number displays N pieces of data

SELECT * FROM table limit 0,5;

Effect:

As shown in the figure, five pieces of data are queried. The query starts with the first item and contains five data points. Why does it start at zero? Because we’re counting 0.0 from 0.

Example:

In actual projects, we generally add labels:This statement is added to the end of the SQL statement, as shown in the figure above. The statement is executed only if neither value is null. We generally do not define startPos and pageSize values ourselves, most of which are passed to us from the front end for easy debugging and display.

Mysql — Implementation of Chinese number sort (FIELD)

Today, WE met a requirement to sort the output grid information, but the data was inserted by a third party, which did not give us a good order. So I had to do it myself.

Here is the raw data:

We need to print it in ascending order. Use the mysql function FIELD. The syntax is as follows:

SELECT the identifier FROM the table name ORDER BY FIELD (SUBSTRING (identifier, 3, 1), 'a', '2', '3', '4', '5', '6', '7', '8', '9');Copy the code

The SUBSTRING is used to intercept the ORDER BY which we want to sort. This is similar to Java SUBSTRING. 3) “one”, this is our custom sorting rules, we can also define from the largest to the smallest, even not in order, simply means we define the sorting rules!

Output effect:

Okay, it’s that simple!


Don’t get lost oh ~