MYSQL通过升序和降序排序 [英] MYSQL order by both Ascending and Descending sorting
本文介绍了MYSQL通过升序和降序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有产品的mysql表.
I have a mysql table with products.
产品具有类别ID和名称.
The products have a category ID and a name.
我想做的是按类别ID先降序排列,然后再按产品名称升序排列.
What I'd like to do is order by category id first descending order and then order by product name ascending order.
SELECT * FROM `products` ORDER BY `products`.`product_category_id`,`naam` DESC
我想要的是
SELECT * FROM `products` ORDER BY `products`.`product_category_id`,`naam` DESC,ASC
但是不幸的是,这不起作用.
but that unfortunately doesn't work.
在mysql中甚至可以定义第二个排序列的排序顺序吗?
Is this even possible in mysql to define the sorting order of the second sorting column?
推荐答案
您可以通过以下方式做到这一点:
You can do that in this way:
ORDER BY `products`.`product_category_id` DESC ,`naam` ASC
看看 ORDER BY
优化
这篇关于MYSQL通过升序和降序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文