myql GROU_CONCAT 与FIND_IN_SET查询结果为空问题解决
-
有两张表,表结构如下,右边是hot_incident数据
-
-
hot_event_person_ids以字符串的形式存多个hot_person表里的id
-
hot_person数据如下
-
需求: 根据hot_person表里id为2的用户与hot_incident.hot_event_person_ids对应的所有的incident_title的拼接,中间用逗号隔开
实现:
SELECT
hp.id id,
hp.NAME NAME,
‘事件人物’ AS labelName,
hp.keyword AS keyword,
GROUP_CONCAT(hi.incident_title)
FROM
hot_person hp,hot_incident
hi
WHERE
hp.STATUS = 1
AND hp.id = 2
AND FIND_IN_SET(hp.id, hi.hot_event_person_ids);
发现查出的是null
排查原因,发现是hot_person表的id创建的时候设置了fillzero属性,
解决方案:1. 去掉hot_person表id 的fillzero属性
解决方案: 2. hot_incident.hot_event_person_ids存id的时候补零。
解决后效果: