Count occurrences of a word in string

From LemonWiki共筆
Revision as of 14:49, 7 August 2019 by Planetoid (talk | contribs) (Created page with "Count occurrences of a word in string == Excel == Using the function [https://support.office.com/zh-tw/article/substitute-%E5%87%BD%E6%95%B8-6434944e-a904-4336-a9b0-1e58df3bc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Count occurrences of a word in string

Excel

Using the function SUBSTITUTE & LEN functions. demo

MySQL way

SET @paragraph := 'an apple a day keeps the doctor away';
SET @term := 'apple';

SELECT FLOOR((LENGTH(@paragraph) - LENGTH(REPLACE(@paragraph, @term, ''))) / LENGTH(@term)) AS occurrences;