Home >Database >Mysql Tutorial >MYSQL sorting sql statement
The sql statement about MYSQL sorting is mainly composed of desc and asc sorting based on order by. This is also a place that is often used in sql statements. Let me give a simple example below:
If The data in a data table named Tbl is as follows:
#If we need to sort in ascending order according to the value of the gz column, but the value of 0 is at the bottom, then we The result achieved through desc and asc of sql is as follows:
The specific implementation method of sql statement is as follows:
1.order by expression
SELECT nian ,gz from Tbl ORDER BY gz!=0 desc,gz
2. Arithmetic method
SELECT nian ,gz,1/gz as od from Tbl ORDER BY od desc
These two methods can complete the corresponding results according to the needs. They are similar. You can simulate them and realize them according to different needs;
The above is the detailed content of MYSQL sorting sql statement. For more information, please follow other related articles on the PHP Chinese website!