Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count all characters in all rows of a field in MySQL?

Tags:

sql

mysql

I need to character count the sum of all the characters in a text based field in MySQL. I need to know the total number of characters of all the posts in that field combined, and can't think how I'd do this...

Any help would be great.

Thanks.

like image 475
i-CONICA Avatar asked Nov 11 '11 15:11

i-CONICA


People also ask

How do I count characters in a column in MySQL?

MySQL CHAR_LENGTH() function MySQL CHAR_LENGTH() returns the length (how many characters are there) of a given string. The function simply counts the number characters and ignore whether the character(s) are single-byte or multi-byte.

How count all rows in MySQL table?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

How do I count all the values in a column in SQL?

The FROM clause in SQL specifies which table we want to list. You can also use the ALL keyword in the COUNT function. SELECT COUNT(ALL column_name) FROM table_name; The ALL keyword will count all values in the table including duplicates.

How do I count all rows?

If you need a quick way to count rows that contain data, select all the cells in the first column of that data (it may not be column A). Just click the column header. The status bar, in the lower-right corner of your Excel window, will tell you the row count.


1 Answers

For the number of bytes . . .

select sum(length(your_column_name)) 
from your_table_name;

For the number of characters . . .

select sum(char_length(your_column_name)) 
from your_table_name;

The char_length() function accommodates multi-byte characters; five two-byte characters will return as 5.

like image 58
Mike Sherrill 'Cat Recall' Avatar answered Oct 14 '22 08:10

Mike Sherrill 'Cat Recall'