PHP MySQL按多列排序 [英] PHP MySQL Order by multiple columns

查看:67
本文介绍了PHP MySQL按多列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望基于表格中的多列创建订单-所有日期都相关.例如:我的列是:fee_duefee_2_duefee_3_due-它们都包含不同日期的结果.但是,我想创建一个包含所有列的订单,因此fee_due可能是2012-11-03fee_2_due可能是2012-11-01,而fee_3_due可能是2012-11-02.

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. 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.

我的查询必须是:

SELECT *
FROM table_name
ORDER BY [date] DESC

...,从而使3列中的日期结合起来形成一个顺序,而不管它们位于哪一列中.

... whereby the dates from the 3 columns join to form one order, regardless of what column they are in.

希望如此,并提前致谢.

Hope that makes sense and thanks in advance.

推荐答案

此外,您还可以:

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.

这篇关于PHP MySQL按多列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆