一、背景说明 表sys_dept中有个字段 ancestors,ancestors的值是含有“,”(逗号) 现在需要计算“,”(逗号)这个字符串在ancestors中出现的数量 二、解决方案 SELECT dept_id, dept_name, ancestors, round(( CHAR_LENGTH(ancestors) - CHAR_LENGTH(REPLACE(ancestors