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

前端 未结 4 951
天命终不由人
天命终不由人 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 07:00

    Depends what you mean by "string occurs" - as a substring or as full value?

    Full value case:

    SELECT COUNT(*) FROM my_table WHERE my_column = 'my word';
    

    Substring case:

    SELECT COUNT(*) FROM my_table WHERE my_column LIKE '%my word%';
    

提交回复
热议问题