SQL函数获取字符串在列中出现的次数?
是否有用于计算字符串在另一个字符串或列中出现的次数的 MySQL 函数?基本上我想要:
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 word', `my_column`) AS `match_count`
FROM `table`
谢谢!
我需要知道字符串在 SELECT
中的每一行的列中出现多少次.
I need to know how many times the string appears in a column for each row in a SELECT
.
推荐答案
一个明显但不可扩展的方式是这样的
An obvious but unscalable way is like this
(LENGTH(`my_column`) - LENGTH(REPLACE(`my_column`, 'my word', '')))/LENGTH('my word')
您是否调查过全文搜索在 MySQL 中?
Have you investigated Full Text search in MySQL?
相关文章