通过两列订购MySQL表 [英] Order a MySQL table by two columns
本文介绍了通过两列订购MySQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何按两列对MySQL表进行排序?
How do I sort a MySQL table by two columns?
我想要的是文章,首先是最高评分,然后是最新日期.例如,这将是一个示例输出(左#是评分,然后是文章标题,然后是文章日期)
What I want are articles sorted by highest ratings first, then most recent date. As an example, this would be a sample output (left # is the rating, then the article title, then the article date)
50 | This article rocks | Feb 4, 2009
35 | This article is pretty good | Feb 1, 2009
5 | This Article isn't so hot | Jan 25, 2009
我正在使用的相关SQL是:
The relevant SQL I'm using is:
ORDER BY article_rating, article_time DESC
我可以按一个或另一个排序,但不能同时排序.
I can sort by one or the other, but not both.
推荐答案
默认排序是递增的,您需要在两个订单中都添加关键字DESC:
Default sorting is ascending, you need to add the keyword DESC to both your orders:
ORDER BY article_rating DESC, article_time DESC
这篇关于通过两列订购MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文