2012-12-06 29 views
0

你好,我做了一個查詢,其中我根據當前的日期安排數據,但問題是結果是以較舊的形式到較新的。我怎麼能達到這個由更新到更舊。這裏是我的查詢根據時間戳安排數據較舊

$date = "select CAST(post_date AS DATE) AS dated from wp_hdflvvideoshare group by dated order by (DATE_SUB(CURDATE(), INTERVAL 20 DAY))"; 
$date_sql=$wpdb->get_results($date); 

像我在

形式得到結果十月十一月十二月

我希望它在

十二月十一月十月

+0

'(DATE_SUB(CURDATE(),INTERVAL 20 DAY))'是常數日期。它與行沒有關係,因此它不會改變排序。 –

+0

那麼我該如何做這項工作? –

+0

發佈示例數據和預期輸出。 –

回答

1

嘗試此::

select CAST(post_date AS DATE) AS dated from wp_hdflvvideoshare group by dated 
order by dated desc 
+0

dosent可以工作 –

0
$date = "select CAST(post_date AS DATE) AS dated 
      from wp_hdflvvideoshare 
      group by dated 
      order by dated DESC"; 
+0

它在每個月再次重複一切n結果 –

+0

試試這個http://82.157.70.109/mirrorbooks/mysqlcertification/0672326329/ch05lev1sec3.html –

+0

@arvin_codeHunk是不是我所做的? – Barmar