2017-02-10 8 views
0

私はそれがほぼ完璧に動作している、このクエリを持っている:SQLソートの月、1月の後に12月を取得するのはなぜですか?

SELECT tbl.y year, group_concat(month_posts SEPARATOR '-') dates 
    FROM (
     SELECT YEAR(p.post_date) y, MONTH(p.post_date) m, concat(MONTH(p.post_date), ':', group_concat(p.id ORDER BY p.post_date ASC)) month_posts 
     FROM prt_posts p  
     WHERE (p.post_status = 'publish' OR p.post_status = 'future') 
      AND p.post_type = 'EVENT' 
      AND p.post_date <= DATE('2016-12-31 00:00:00') 
     GROUP BY y, m 
     ORDER BY y, m ASC 
    ) tbl 
GROUP BY tbl.y 
ORDER BY tbl.y DESC 

出力は年、この形式で日付:

月:ID、ID、ID-月:ID、ID、 id-etc ..

私の問題は、結果には、1月の直後に12月が表示されていることです。

enter image description hereあなたが第二列に見ることができるように、私は1持って

:128、12:138など、その1(1月)、右後2(12月)。どうして?私にとっては、今解決のために

答えて

0

は、最初の行にORDER BY tbl.mを追加しました:

SELECT tbl.y year, group_concat(month_posts ORDER BY tbl.m SEPARATOR '-') dates 
関連する問題