1. 程式人生 > >mysql中某個欄位中其中一個字元出現的次數

mysql中某個欄位中其中一個字元出現的次數

利用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