SELECT `film_id`,COUNT(film_id) AS COUNT FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY film_id,COUNT
HAVING COUNT = 1
回報:
film_id | COUNT
7 1
6 1
但我想它返回:
film_id
7
6
我怎麼只返回1個colomn?
SELECT `film_id`,COUNT(film_id) AS COUNT FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY film_id,COUNT
HAVING COUNT = 1
回報:
film_id | COUNT
7 1
6 1
但我想它返回:
film_id
7
6
我怎麼只返回1個colomn?
要做到這一點,只需移動你的「COUNT(film_id)
」。您的HAVING
條款將爲您完成這項工作。
SELECT `film_id` FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY anime_id,film_id
HAVING COUNT(film_id) = 1
'GROUP BY anime_id,COUNT(film_id)回答了'我會說... – Wrikken 2010-07-08 10:59:34
我認爲這將沒有什麼區別,因爲目標是刪除計數字段形式的選擇,並選擇行其中film_id == 1 – 2010-07-08 11:07:25
非常感謝pranay – meotimdihia 2010-07-10 07:51:39
這不是一個CakePHP問題,儘管它被標記爲這樣。
然而,在CakePHP中:
$this->FilmGenre->find('list',array('fields'=>array('film_id','film_id','anime_id')));
通過pranay和madhiva – meotimdihia 2010-07-10 07:57:27