-4

这是我的选择查询,

select rac_username, rac_profilepicture, tafd_postid, tafd_postcontent, tafd_postimage_source, DATE_FORMAT(tafd_postadded,'%M %d, %Y') tafd_postadded,tafd_imotion, (select count(rpg_actormakeget) from r_post_getyou where rpg_postrelate = tafd_postid and rpg_isremoved = 0) as tafd_igetyoucount, (select count(rpg_postrelate) from r_post_getyou where rpg_postrelate = tafd_postid and rpg_actormakeget = (select rac_accountid from r_account_credentials where rac_username = 'zheuswalker' )) as isliked, (select count(rfc_commentid) from r_feeds_comments where rfc_feedparent = tafd_postid) rfc_commentcount from t_account_feeds inner join r_account_credentials on r_account_credentials.rac_accountid = t_account_feeds.tafd_postcreator  
ORDER BY STR_TO_DATE (tafd_postadded,'%M %d, %Y') ASC

我已经尝试按 desc 排序日期,但我仍然没有得到预期的结果。我希望日期将按升序排序(最新到最旧)。

我也尝试通过这个(ORDER BY tafd_postadded asc)订购它并查看图片,请注意 2019 年 3 月介于 2018 年 6 月和 2018 年 11 月之间

4

2 回答 2

0

我在我的 tafd_postadded 列上使用日期时间,所以在排序日期时间时我们应该使用UNIX_TIMESTAMP();

select * from table order by UNIX_TIMESTAMP(datetime column) desc
于 2019-10-03T11:09:26.320 回答
0

STR_TO_DATE 比较字符串,因此 Mars 在 11 月之前是正常的,因为字母 M 在字母 N 之前。

你应该做 :

ORDER BY tafd_postadded DESC

Desc 最新到最旧
Asc 最旧到最新

于 2019-03-01T15:50:40.893 回答