PHP query MySQL in the value of a field within a certain number of occurrences of the text, how to solve

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.