批量更新逗号隔开的名称 (部门里面将多个用逗号隔开的ID转换成用逗号隔开的名称)(mysql)

来源:互联网 发布:乐知英语好不好 编辑:程序博客网 时间:2024/06/10 10:46
update dept b, (select group_concat(t.deptId), group_concat(d.deptName separator '/') as dName, t.id, t.deptName from (select substring_index(substring_index(a.deptId,',',b.help_topic_id+1),',',-1) as deptId, a.id, a.deptName
from  
(select d.father AS deptId , d.id, d.deptName
 from dept d ) a
join mysql.help_topic b on b.help_topic_id < (length(a.deptId) - length(replace(a.deptId,',',''))+1)) t LEFT JOIN dept d on t.deptId = d.id  where t.deptId != ''

GROUP BY id, deptName ) c set b.location=c.dName where b.id = c.id


效果如图


0 0
原创粉丝点击