MySQL自定义订单 [英] MySQL Custom Order
本文介绍了MySQL自定义订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,我从中选择数据,该表中的列称为parent,它是无符号整数类型.
I have a table that I select data from with a column called parent that's of unsigned integer type.
它的数字从0到12.
我想按父级asc从表顺序开始select *
,但有一个例外:将0放在选择的末尾,这样就像1,2,3,4,5,6,7,8,9,0
.
I want to select *
from table order by parent asc, but with one exception: place the 0 at the end of the select so it would be like 1,2,3,4,5,6,7,8,9,0
.
在MySQL中只需一次选择就可以吗?
Is this possible with a single select in MySQL please?
推荐答案
我会做这样的事情:
select *
from your_table
order by (parent != 0) desc, parent asc;
这篇关于MySQL自定义订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文