MySQL +计算列中的所有单词 [英] Mysql + count all words in a Column

查看:168
本文介绍了MySQL +计算列中的所有单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个表中有2列,我想大致"报告单词总数. 是否可以运行MySQL查询并找出一列中的单词总数.

I have 2 columns in a table and I would like to 'ruffly' report on the total number of words. Is it possible to run a MySQL query and find out the total number of words down a column.

基本上是任何由空格或多个空格分隔的文本. 只需作为一般指南,就不必100%准确.

It would basically be any text separated by a space or multiple space. Doesn't need to be 100% accurate as its just a general guide.

可能吗?

thx

推荐答案

尝试如下操作:

SELECT COUNT(LENGTH(column) - LENGTH(REPLACE(column, ' ', '')) + 1)
FROM table

这将计算您列中的角色数量,并减去列中的角色数量,以删除所有空格.据此,您知道行中有多少空格,并因此知道有多少个单词(大致是因为您也可以键入一个双精度空格,所以这将算作两个单词,但是您说要使它粗略,因此就足够了).

This will count the number of caracters in your column, and substracts the number of caracters in your column removing all the spaces. Hereby you know how many spaces you have in your row and hereby know how many words there are (roughly because you can also type in a double space, this wil count as two words but you say you want it ruffly so this should suffice).

这篇关于MySQL +计算列中的所有单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆