gpt4 book ai didi

mysql - 选择group_concat()包含字符的记录

转载 作者:行者123 更新时间:2023-11-29 07:22:57 24 4
gpt4 key购买 nike

如何选择仅包含 0 的 mystatus 字段

select c.id,count(*),
group_concat(distinct(r.status not in ('Done','None'))) as mystatus
from cases c inner join reports r
on (c.id = r.parent_id and r.parent_type = 'Cases' and r.deleted = 0)
where c.deleted = 0
and c. status <> 'Late'
group by c.id

结果看起来像这样,但我只想选择包含 0 的 mystatus

ID  count(*)  mystatus
A 1 0
B 7 0,1
C 2 0

应该选择记录ID A和C

最佳答案

添加 HAVING 子句。

select c.id,count(*),
group_concat(distinct(r.status not in ('Done','None'))) as mystatus
from cases c inner join reports r
on (c.id = r.parent_id and r.parent_type = 'Cases' and r.deleted = 0)
where c.deleted = 0
and c. status <> 'Late'
group by c.id
having mystatus = '0'

关于mysql - 选择group_concat()包含字符的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35476089/

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