PHP queries the number of occurrences of a text in a field value in MySQL
I have a MySQL table named: Name, there is a field caozuo, there are fields: Zhuangtai
Which, in the Caozuo field, is an operation of the row data, now because of business needs, need to count operations 3 times the amount of data below!
This needs to query the Caozuo field, a paragraph of the number of text appears, because of the front office business, each time a change, the Caozuo field will be inserted in some notes, but there is a uniform paragraph format of the text, the paragraph format is:
----"Edit time: 2012-09-24 11:11:42"----But the format is certain, the content is not the same! The editing time is automatically inserted! To put it simply, I need a query statement that counts:
Within the query database, the number of "edit time" occurrences less than 3 times in the Caozuo field of Zhuangtai 1
Do not know how to query it?
------Solution--------------------
Count the number of "edit time" occurrences in the Caozuo field
(Length (Caozuo)-Length (Replach (Caozuo, ', ' Edit Time '))/Length (' Edit Time ')
This formula should not be difficult to understand, right?
With this, it's going to be easy.
SELECT * from name where zhuangtai= ' 1 ' and (length (Caozuo)-Length (Replach (Caozuo, ' ', ' edit Time '))/Length (' Edit Time ') < 3