使用 SQL 计算列中的单词


Count words in column with SQL

id | words                            | other
1  | lorem ipsum                      | dsf
2  | Lorem Ipsum is simply dummy text | sads
3  | simply dummy text                | sdf
4  | Lorem Ipsum  text                | sdfsdf
5  | simply dummy Lorem               | asddasd 

我确实从单词中选择 * .我怎么能算出这个查询答案中有多少个字?在此示例中应为 17。我使用PHP和Doctrine。

SELECT LENGTH(words) - LENGTH(REPLACE(words, ' ', '')) + 1 AS words_count
FROM table_name
SELECT SUM( LENGTH(words) - LENGTH(REPLACE(words, ' ', ''))+1)
FROM table