如何将所有字数统计为mysql

I already know how to count words in each row like this:

SELECT *,
IF(words <> '', (length(words)-length(replace(words,' ',''))+1), 0) AS words_count
FROM table

But now i need to SUM all counts from all rows.

How do i do it?

Thank you all.

If you want the sum, use an aggregation query:

SELECT sum(if(words <> '', (length(words)-length(replace(words,' ',''))+1), 0)) AS words_count
FROM table;

EDIT:

If there are no rows, you can do this to avoid NULL values:

SELECT coalesce(sum(if(words <> '', (length(words)-length(replace(words,' ',''))+1), 0)), 0) AS words_count
FROM table;