Count occurrences of a word in string: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
(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...")
(No difference)

Revision as of 14:49, 7 August 2019

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;