Count occurrences of character in a string using MySQL

前端 未结 3 1696
旧时难觅i
旧时难觅i 2021-01-03 22:55

Example Words: a, akkka, akokaa, kokoko, kakao, oooaooa, kkako, kakaoa

I need the regexp witch gives words with 2 or less \'a\' but not the words without \'a\'

3条回答
  •  抹茶落季
    2021-01-03 23:45

    select *  
    from table  
    where  LENGTH(name) - LENGTH(REPLACE(name, 'a', '')) between 1 and 2
    

    Updated to use between.

提交回复
热议问题