select group_concat(bookgenre), author_authorID
from Written
group by author_authorID;

给我
桌子
group_conat(bookgenre)      author_authorID
Fiction                     123450
Fiction, History            123451
History                     123457
Sci-Fi                      123458
Fiction                     123459

我不知道该怎么做
group_concat(bookgenre)     author_authorID
Fiction                     123450
Fiction                     123459

当我添加条件时
where "group_concat(bookgenre)" like 'Fiction'

结果返回0行

最佳答案

你可以这样做

select group_concat(bookgenre), author_authorID
from Written
group by author_authorID;
having count(*) = sum(bookgenre = 'Fiction')

或使用having子句筛选聚合函数的结果
select group_concat(bookgenre), author_authorID
from Written
group by author_authorID;
having group_concat(bookgenre) = 'Fiction'

关于mysql - GROUP_CONCAT-位置条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46217339/

10-11 08:59