mysql order by 多字段排序

轉載:http://blog.csdn.net/xlxxcc/article/details/52250963 (MySql Order By 多個字段 排序規則)

轉載:http://www.manongjc.com/article/1085.html

mysql單個字段降序排序:

select * from table order by id desc;

mysql單個字段升序排序:

select * from table order by id asc;

mysql多個字段排序:

select * from table order by id desc,name desc;

多字字段排序只需要添加多個排序條件,並且每個排序的條件之前用逗號分開。

order by id desc,name desc; 表示先按照id降序排序,再按照name降序排序。

同理:

order by id desc,name asc; 表示先按照id降序排序,再按照name升序排序。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章