[英]How to sort two different date columns in mysql in descending order?
有人可以帮助我如何在mysql中对两个不同的日期列进行排序吗?
我使用具有两个不同列的表创建了一个查询。 第一个是cert_date,另一个是special_training_date_from。 我想做的是执行查询时,输出必须是这样的:cert_date和special_training_date_from列必须以降序排列在一起。 例如,如果cert_date为'2012-01-03,2012-07-07'和special_training_date_from为'2011-05-03,2013-08-01',则输出必须为:
2013-08-01, 2012-07-07, 2012-01-03, 2011-05-03
这是我使用过的查询。
Select training_title, cert_date, special_training_date_from
from tabletraining
order by cert_date + sptrain_from desc;
每次我按升序排序结果都是正确的,但是我想按降序排序,并且每次我输入'desc'关键字时,结果都会变得不正确。
您可以将日期放在一列中order by
以下order by
使用order by
:
select training_title, thedate, which
from ((Select training_title, cert_date as thedate, 'cert' as which
from tabletraining
) union all
(select training_title, special_training_date_from, 'special' as which
from tabletraining
)
) t
order by thedate desc;
编辑:
如果只想在两列中使用不同的日期,请使用:
select distinct thedate
from ((Select training_title, cert_date as thedate, 'cert' as which
from tabletraining
) union all
(select training_title, special_training_date_from, 'special' as which
from tabletraining
)
) t
order by thedate desc;
尝试这个...
order by CONCAT(cert_date,sptrain_from) desc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.