0

誰かが mysql で 2 つの異なる日付列をソートする方法を教えてくれますか?

2 つの異なる列を持つテーブルを使用してクエリを作成しました。1 つは cert_date で、もう 1 つは 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」キーワードを入力するたびに結果が正しくなくなります。

4

2 に答える 2

0

使用する単一の列に日付を入れることができます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;

編集:

2 つの列で異なる日付だけが必要な場合は、次を使用します。

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;
于 2013-08-01T01:27:32.460 に答える
0

これを試して...

order by CONCAT(cert_date,sptrain_from) desc;
于 2014-02-12T08:43:10.867 に答える