• <small id='oB9A1'></small><noframes id='oB9A1'>

  • <i id='oB9A1'><tr id='oB9A1'><dt id='oB9A1'><q id='oB9A1'><span id='oB9A1'><b id='oB9A1'><form id='oB9A1'><ins id='oB9A1'></ins><ul id='oB9A1'></ul><sub id='oB9A1'></sub></form><legend id='oB9A1'></legend><bdo id='oB9A1'><pre id='oB9A1'><center id='oB9A1'></center></pre></bdo></b><th id='oB9A1'></th></span></q></dt></tr></i><div id='oB9A1'><tfoot id='oB9A1'></tfoot><dl id='oB9A1'><fieldset id='oB9A1'></fieldset></dl></div>
    1. <legend id='oB9A1'><style id='oB9A1'><dir id='oB9A1'><q id='oB9A1'></q></dir></style></legend><tfoot id='oB9A1'></tfoot>

          <bdo id='oB9A1'></bdo><ul id='oB9A1'></ul>

        计算字符串在 VARCHAR 字段中出现的次数?

        时间:2023-08-19
          <tbody id='kqtht'></tbody>
        1. <small id='kqtht'></small><noframes id='kqtht'>

        2. <legend id='kqtht'><style id='kqtht'><dir id='kqtht'><q id='kqtht'></q></dir></style></legend>

            <tfoot id='kqtht'></tfoot>

                <bdo id='kqtht'></bdo><ul id='kqtht'></ul>

                • <i id='kqtht'><tr id='kqtht'><dt id='kqtht'><q id='kqtht'><span id='kqtht'><b id='kqtht'><form id='kqtht'><ins id='kqtht'></ins><ul id='kqtht'></ul><sub id='kqtht'></sub></form><legend id='kqtht'></legend><bdo id='kqtht'><pre id='kqtht'><center id='kqtht'></center></pre></bdo></b><th id='kqtht'></th></span></q></dt></tr></i><div id='kqtht'><tfoot id='kqtht'></tfoot><dl id='kqtht'><fieldset id='kqtht'></fieldset></dl></div>
                • 本文介绍了计算字符串在 VARCHAR 字段中出现的次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一张这样的桌子:

                  TITLE          |   DESCRIPTION
                  ------------------------------------------------
                  test1          |   value blah blah value
                  test2          |   value test
                  test3          |   test test test
                  test4          |   valuevaluevaluevaluevalue
                  

                  我想弄清楚如何返回字符串在每个描述中出现的次数.

                  I am trying to figure out how to return the number of times a string occurs in each of the DESCRIPTION's.

                  所以,如果我想统计'value'出现的次数,sql语句会返回这个:

                  So, if I want to count the number of times 'value' appears, the sql statement will return this:

                  TITLE          |   DESCRIPTION                  |   COUNT
                  ------------------------------------------------------------
                  test1          |   value blah blah value        |   2
                  test2          |   value test                   |   1
                  test3          |   test test test               |   0
                  test4          |   valuevaluevaluevaluevalue    |   5
                  

                  有没有办法做到这一点?我根本不想用php,就用mysql.

                  Is there any way to do this? I do not want to use php at all, just mysql.

                  推荐答案

                  这应该可以解决问题:

                  SELECT 
                      title,
                      description,    
                      ROUND (   
                          (
                              LENGTH(description)
                              - LENGTH( REPLACE ( description, "value", "") ) 
                          ) / LENGTH("value")        
                      ) AS count    
                  FROM <table> 
                  

                  这篇关于计算字符串在 VARCHAR 字段中出现的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:FIND_IN_SET() 与 IN() 下一篇:MySQL,一次查询更新多张表

                  相关文章

                  最新文章

                  <i id='CFNoe'><tr id='CFNoe'><dt id='CFNoe'><q id='CFNoe'><span id='CFNoe'><b id='CFNoe'><form id='CFNoe'><ins id='CFNoe'></ins><ul id='CFNoe'></ul><sub id='CFNoe'></sub></form><legend id='CFNoe'></legend><bdo id='CFNoe'><pre id='CFNoe'><center id='CFNoe'></center></pre></bdo></b><th id='CFNoe'></th></span></q></dt></tr></i><div id='CFNoe'><tfoot id='CFNoe'></tfoot><dl id='CFNoe'><fieldset id='CFNoe'></fieldset></dl></div>
                • <small id='CFNoe'></small><noframes id='CFNoe'>

                  <tfoot id='CFNoe'></tfoot>

                  • <bdo id='CFNoe'></bdo><ul id='CFNoe'></ul>
                  <legend id='CFNoe'><style id='CFNoe'><dir id='CFNoe'><q id='CFNoe'></q></dir></style></legend>