mysql中某个字段中其中一个字符出现的次数

来源:互联网 发布:北明软件待遇 编辑:程序博客网 时间:2024/06/11 19:03

利用Mysql提供的replace、length方法完美解决

select name,term_id,parent,path from terms
where status = 1 and  parent = 0  --仅一级分类
--过滤掉没有子分类的分类
--length(path)-length(replace(path,'-','')) 统计path列字符串中’-‘出现的次数
--大于1表明至少有两个父分类
and  term_id not in
(select parent from terms where length(path)-length(replace(path,'-',''))>1)
 order by listorder asc,term_id asc

阅读全文
0 0
原创粉丝点击