GROUP BY 和 GROUP_CONCAT的使用

时间:2022-12-18 21:12:04
select b.templateId,GROUP_CONCAT(c.id),a.executeResult 
from vrv_paw_rulestatus a, vrv_paw_terminaltobaselinereport b, vrv_paw_rule c, vrv_paw_template_rule d
where a.terOnlyId = b.terminalInfoId and b.templateId = d.templateId and d.ruleOnlyId = c.id
GROUP BY b.templateId,a.executeResult

GROUP BY 和 GROUP_CONCAT的使用

原来的数据:

select b.templateId,c.id,a.executeResult from vrv_paw_rulestatus a, vrv_paw_terminaltobaselinereport b, vrv_paw_rule c, vrv_paw_template_rule d
where a.terOnlyId = b.terminalInfoId and b.templateId = d.templateId and d.ruleOnlyId = c.id

GROUP BY 和 GROUP_CONCAT的使用

与我需要的数据不一样

加group by只加一个:id不全,丢失了;executeResult也丢失了

select b.templateId,c.id,a.executeResult from vrv_paw_rulestatus a, vrv_paw_terminaltobaselinereport b, vrv_paw_rule c, vrv_paw_template_rule d
where a.terOnlyId = b.terminalInfoId and b.templateId = d.templateId and d.ruleOnlyId = c.id
GROUP BY b.templateId

GROUP BY 和 GROUP_CONCAT的使用