【发布时间】:2014-08-02 18:11:13
【问题描述】:
我是 PHP 新手。我想计算 MySQL 数据库行中特定单词的出现次数。 例如:有两列名称和描述。
---------------------------------------------------------------
| name | description |
---------------------------------------------------------------
| abcd | My name ***is*** abcd. My father's name ***is*** xyz |
---------------------------------------------------------------
| xyzt | My name ***is*** xyz. I am a good girl. |
---------------------------------------------------------------
我想从第一行描述列中计算单词“is”的出现次数。在上面的示例中,'is' 在第一行出现 两次,在第二行出现 一次。请指导我。
【问题讨论】:
-
对于 SQL 唯一的答案,请参阅stackoverflow.com/questions/12344795/…
-
不投票关闭这个作为上面链接的问题的副本,因为这个问题询问字符串,而这个问题明确询问 words
-
试试从stackoverflow.com/a/396266借来的
select count(*) from yourtable where match(description) against ('is');或从stackoverflow.com/a/395859借来的select count(*) from table where fieldname REGEXP '[[:<:]]word[[:>:]]';