简体   繁体   English

GROUP_CONCAT-位置条件

[英]GROUP_CONCAT - WHERE Condition

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

gives me 给我

table

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

I dont know how to only generation 我不知道该如何一代

group_concat(bookgenre)     author_authorID
Fiction                     123450
Fiction                     123459

When I add the condition 当我添加条件

where "group_concat(bookgenre)" like 'Fiction'

It results with 0 rows returned 结果返回0行

Group_concat is an aggregated function so you should filter using having and not where Group_concat是一个聚合函数,因此您应该使用had和not where进行过滤
And for like you should use wildchar % 而且对于你应该使用wildchar %

select group_concat(bookgenre), author_authorID
from Written
group by author_authorID;
havine group_concat(bookgenre) LIKE '%fiction%'

You can do so by 你可以这样做

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

or use having clause to filter result of aggregate functions 或使用Have子句过滤聚合函数的结果

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM