简体   繁体   English

PHP MySQL按多列排序

[英]PHP MySQL Order by multiple columns

I am looking to create an order based on multiple columns in my table - all date related. 我希望基于我的表中的多个列创建一个订单 - 所有日期相关。 For example: my columns are: fee_due , fee_2_due , fee_3_due - they all contains results of various dates. 例如:我的列是: fee_duefee_2_duefee_3_due - 它们都包含各种日期的结果。 However, I want to create an order combining all columns, so fee_due might be 2012-11-03 , fee_2_due might be 2012-11-01 and fee_3_due might be 2012-11-02 . 但是,我想创建一个组合所有列的订单,因此fee_due可能是2012-11-03fee_2_due可能是2012-11-01fee_3_due可能是2012-11-02

My query needs to be: 我的查询需要是:

SELECT *
FROM table_name
ORDER BY [date] DESC

... whereby the dates from the 3 columns join to form one order, regardless of what column they are in. ...其中3列的日期连接形成一个订单,无论它们在哪个列中。

Hope that makes sense and thanks in advance. 希望有意义并提前感谢。

Additionally you can: 此外,您可以:

SELECT *
FROM table_name
ORDER BY fee_due ASC,fee_2_due DESC,fee_3_due DESC

You can sort each column independently according to your need. 您可以根据需要单独对每列进行排序。

我使用以下方法使其工作:

SELECT * FROM table ORDER BY camp1 ASC, camp2 ASC, camp3 DESC

Have you try this: 你试试这个:

SELECT *
FROM table_name
ORDER BY fee_due,fee_2_due,fee_3_due DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM