SQL function to get count of how many times string appears in column?

前端 未结 4 934
天命终不由人
天命终不由人 2020-12-17 06:29

Is there a function for MySQL that will count the number of times a string occurs in another string or column? Basically I want:

SELECT
    SUB_COUNT(\'my wo         


        
4条回答
  •  误落风尘
    2020-12-17 06:57

    An obvious but unscalable way is like this

    (LENGTH(`my_column`) - LENGTH(REPLACE(`my_column`, 'my word', '')))/LENGTH('my word')
    

    Have you investigated Full Text search in MySQL?

提交回复
热议问题