如何按两列对 MySQL 表进行排序?
我想要的是首先按最高评分排序的文章,然后是最近的日期。例如,这将是一个示例输出(左 # 是评分,然后是文章标题,然后是文章日期)
+================+=============================+==============+ | article_rating | article | article_time | +================+=============================+==============+ | 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 | +================+=============================+==============+
The relevant SQL I'm using is:
ORDER BY article_rating, article_time DESC
我可以按其中一个排序,但不能同时排序。
最佳答案
默认排序是升序,您需要在两个订单中添加关键字DESC:
ORDER BY article_rating DESC, article_time DESC
关于mysql - 按两列对 MySQL 表排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/514943/