【问题标题】:JSON_SEARCH and Regex in mysqlmysql 中的 JSON_SEARCH 和正则表达式
【发布时间】:2021-07-11 03:30:05
【问题描述】:

我的 JSON 看起来像

user1--> 
{"feeds": [{"trait": "ms", "rating": "5", "observation": "fstress", "riskscaling": "3"}, {"trait": "es", "rating": "7", "observation": "abcde", "riskscaling": 6}], "ad_countryCode": "91"}

如果我想为拥有fstress 的用户找到价值,那么我将使用查询作为-

SELECT DISTINCT globalusers.id 
FROM globalusers 
WHERE (JSON_SEARCH(dynamic_attributes->>'$.feeds[*].observation','all', 'fstress'));

然后我正在获取我的用户 ID,但现在我想使用正则表达式来查找具有 {fstress} 的用户 有人帮忙吗?

【问题讨论】:

  • 愿意为这样的用户举个例子吗?

标签: mysql regex


【解决方案1】:

同样的工作Qry--> SELECT globalusers.id FROM globalusers WHERE dynamic_attributes->>'$.feeds[*].observation' REGEXP 'fstress';

【讨论】:

    【解决方案2】:

    只需包含字符串fstress ?

    SELECT globalusers.id FROM `globalusers ` WHERE address REGEXP 'fstress';
    

    【讨论】:

    • 这个 qry 对我有用-->SELECT globalusers.id FROM globalusers WHERE dynamic_attributes->>'$.feeds[*].observation' REGEXP 'fstress';
    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2011-10-05
    相关资源
    最近更新 更多