Counting the number of rows that have a particular word in a column of blob data type in mysql

老子叫甜甜 提交于 2019-12-12 01:22:55

问题


I have a table like this in mysql. The datatype of column 'file' is blob. I need to count the number of rows which have the word 'lumia' in column 'file' and 'display' in column 'attribute'. That is, here the rows 1 and 3. so the output has to be 2. How can i do that in mysql?

The multiple occurrence of the word lumia in 3rd row need not be counted twice.

  +------+----------------------------+------------+
  | slno | file                       | attribute  | 
  +------+----------------------------+------------+
  |    1 | 5inch 8mp lumia snapdragon | display    |
  |
  |    2 | 8mp galaxy samsung android | camera     | 
  |
  |    3 | nokia lumia red lumia      | display    |
  |
  |    4 | black samsung 8mp android  | camera     |
  |
  |    5 | lumia windows 8mp red      | model      |

回答1:


In addition to what is stated in How to count the number of occurrences of a particular word in a MySQL blob text?

If you need to get the sum try something like this

SELECT SUM(IF(LOCATE(@searchthis, file),1,0)) AS Count_Sum FROM  `documents`;

Excluding the SUM() the results are like below as stated in condition "The multiple occurrence of the word lumia in 3rd row need not be counted twice"



来源:https://stackoverflow.com/questions/29454938/counting-the-number-of-rows-that-have-a-particular-word-in-a-column-of-blob-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!