2013-12-19 29 views
1

檢查下面的代碼只得到一年:如何從日期CakePHP中使用不同於MySQL的

$this->set('hi', $this->posts->find('all', 
array('fields'=>array('DISTINCT year(posts.Post_date)')))); 

,我沒有得到正確的結果...誰能幫我在這,請...

我的查詢是(從帖子中選擇不同年份(post_date));

感謝

+1

使用的格式(字段名, 'Y')作爲你的約會 –

+0

http://dev.mysql.com /doc/refman/5.1/en/string-functions.html#function_format –

+0

同時檢查您的大小寫,您可能需要將「posts.Post_date」替換爲「Posts.post_date」。 –

回答

3

下面替換下面

`DISTINCT year(posts.Post_date)` 

: -

YEAR(DISTINCT posts.Post_date) as year 
+0

@saimurali如果這個答案可以幫助你然後PLZ接受這個答案。 – ripa

相關問題