把逗号去掉前后到长度差就是逗号到数目

select id, (length(string)-length(replace(string, ',',''))) as cnt
from strings;