我需要一些关于MYSQL查询的正则表达式的帮助来搜索包含具有精确模式的单元格的行.我是MYSQL正则表达式的新手.
这是一个名为test_table的示例表(json_value是数组的json字符串)
|id | json_value ----------------------------------------------------------------------------------------------- | 1 | {"field_198":false,"field_4":"From quality office","field_9":"product with high quality","field_10":"comment"} | 2 | {"field_198":true,"field_4":"From ordering office","field_9":"back to quality office","field_10":"comment"} | 3 | {"field_198":true,"field_4":"From ordering office","field_9":"cancelled","field_10":"comment"} | 4 | {"field_198":true,"field_4":"Return to quality office","field_9":"product ok","field_10":"comment"}
如果我想获得所有行:
- field_4 containing "quality" string, the query should to return id 1 and 4 - field_9 containing "quality" string, the query should to return id 1 and 2 - field_4 containing "ordering" string, the query should to return id 2 and 3
我希望这个例子是结论性的.
我试过使用这个查询
SELECT id from test_table WHERE json_value REGEXP 'field_4":".*quality.*';
但返回id 1,2和4因为贪婪并在第2行的field_9找到"质量"
另一个问题是(我知道,这是一个愚蠢的正则表达式)
SELECT id from test_table WHERE json_value REGEXP 'field_4":"[^quality]*quality.*';
但只返回id 1
我在互联网上发了很多帖子但没有成功.正则表达式如何获得正确的行?
编辑还有 一个想法,更明确的是,第一个来自搜索的工作是来自数组的完整键,但第二个是部分值,如"%substring%"
谢谢