MySQL conditional ORDER BY ASC/DESC for date column

后端 未结 4 1783
太阳男子
太阳男子 2020-12-19 04:33

I need a MySQL conditional ORDER BY statement for a datetime field. I have a table with posts which I would like to order in the following way: all future posts

4条回答
  •  无人及你
    2020-12-19 05:19

    How about something like this? Select twice and union the results.

    Select * from (SELECT post_status, post_date, post_title 
    FROM wp_posts WHERE post_status IN ('future') 
    ORDER BY post_status ASC  ) alias1  
    UNION
    Select * from (SELECT post_status, post_date, post_title 
    FROM wp_posts WHERE post_status IN ('publish') 
    ORDER BY post_status DESC ) alias2  
    

提交回复
热议问题