Home > Database > Mysql Tutorial > body text

MYSQL sorting sql statement

ringa_lee
Release: 2017-07-13 17:18:32
Original
2247 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!