vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I'm running MySQL 5.0.15 on Windows system. How do I count how many specific char is there in a column, for example finding 'c' in lowercase string of "Characteristics" would total to 3. -- -------------------------------------------------------------------- `Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe. -------------------------------------------------------------------- |
| ||||
| Hi, MySQL dosen't have built-in function for counting substring. But we can create user-defined functions for this. Like, CREATE FUNCTION substrCount(x varchar(255), delim varchar(12)) returns int return (length(x)-length(REPLACE(x, delim, '')))/length(delim); Then try, SELECT substrCount('Characteristics', 'c') as count; which returns 3. For more reference http://dev.mysql.com/doc/refman/5.0/...functions.html Thanks, ViSolve DB Team. ----- Original Message ----- From: "Scott Hamm" <linuxgold@gmail.com> To: "'Mysql '" <mysql@lists.mysql.com> Sent: Tuesday, October 10, 2006 10:58 PM Subject: Counting char in a column > I'm running MySQL 5.0.15 on Windows system. > > How do I count how many specific char is there in a column, for example > finding 'c' in lowercase string of "Characteristics" would total to 3. > > > > > -- > -------------------------------------------------------------------- > `Twas brillig, and the slithy toves > Did gyre and gimble in the wabe: > All mimsy were the borogoves, > And the mome raths outgrabe. > -------------------------------------------------------------------- > |