SQL函数来计算字符串出现在列中的次数? [英] SQL function to get count of how many times string appears in column?

查看:148
本文介绍了SQL函数来计算字符串出现在列中的次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有MySQL的函数可以计算一个字符串在另一个字符串或列中出现的次数?基本上我想:

pre $ SELECT
SUB_COUNT('my word',`my_column`)AS`match_count`



$ b $ p
$ b $ p

谢谢!

<编辑:
我需要知道字符串出现在 SELECT 中每行的列的次数。 p>

解决方案

显而易见的方式就是这样

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

您是否调查了全文在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`

Thanks!

EDIT: 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')

Have you investigated Full Text search in MySQL?

这篇关于SQL函数来计算字符串出现在列中的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆