gpt4 book ai didi

mysql - GROUP_CONCAT - WHERE 条件

转载 作者:行者123 更新时间:2023-11-29 03:20:23 25 4
gpt4 key购买 nike

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 - WHERE 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46217339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com