问题
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