2014-08-28 29 views
0

裏面我想執行這個查詢,但它在幾個月返回一個空單元格:DATE_FORMAT一個GROUP_CONCAT

SELECT 
year(publication) AS year, 
GROUP_CONCAT(DISTINCT DATE_FORMAT(month(publication), '%M') ORDER BY month(publication) ASC) AS months 
from texts 
GROUP BY year(publication) ORDER BY year (publication) DESC 

Whitout DATE_FORMAT,查詢工作正常。但我需要返回幾個月的名字。

回答

3

更換

DATE_FORMAT(month(publication), '%M') 

DATE_FORMAT(publication, '%M') 
-1

您還可以使用GROUP_CONCAT(from_unixtime(timestamp,'%d-%m-%y %H:%i:%s') separator ', ')

+0

這並不提供答案的問題。一旦你有足夠的[聲譽](https://stackoverflow.com/help/whats-reputation),你將可以[對任何帖子發表評論](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [來自評論](/ review/low-quality-posts/16983146) – PierreDuc 2017-08-09 15:24:30