Count the number of occurrences of a string in a VARCHAR field?

后端 未结 7 1262
花落未央
花落未央 2020-11-22 07:51

I have a table like this:

TITLE          |   DESCRIPTION
------------------------------------------------
test1          |   value blah blah value
test2              


        
7条回答
  •  一向
    一向 (楼主)
    2020-11-22 08:45

    SELECT 
    id,
    jsondata,    
    ROUND (   
        (
            LENGTH(jsondata)
            - LENGTH( REPLACE ( jsondata, "sonal", "") ) 
        ) / LENGTH("sonal")        
    )
    +
    ROUND (   
        (
            LENGTH(jsondata)
            - LENGTH( REPLACE ( jsondata, "khunt", "") ) 
        ) / LENGTH("khunt")        
    )
    AS count1    FROM test ORDER BY count1 DESC LIMIT 0, 2
    

    Thanks Yannis, your solution worked for me and here I'm sharing same solution for multiple keywords with order and limit.

提交回复
热议问题