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

标签 mysql group-concat

如何选择仅包含 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/

相关文章:

MySQL group_concat 和计数

mysql - 在具有多个连接的同一查询中对数据进行分组

mysql - 确定 group_concat MySQL 中项目的年龄

php - GROUP_CONCAT 查询上的 var_dump 不起作用

mysql - SQL 拆分逗号分隔行

javascript - 如何在 JavaScript 中将 MySQL DATETIME 值转换为 json 格式

php - 获取查询结果时格式化日期

mysql - 如何使用任何查询获取具有特定列名的所有表的名称?

mysql - 合并MySQL中的两个表

php - 如何分解由 group_concat[distinct] 合并的值?