【发布时间】:2020-07-28 14:54:16
【问题描述】:
我有一个 MySQL 表,其中有一列类型为 json。此列的值是 json array 而不是 json object。我需要找到该表的记录,其 json 列的至少一个值是给定字符串/短语的子字符串。
假设表格如下所示:
create table if not exists test(id int, col json);
insert into test values (1, '["ab", "cd"]');
insert into test values (2, '["ef", "gh", "ij"]');
insert into test values (3, '["xyz"]');
如果输入字符串/短语是“acf ghi z”,则必须返回第二列作为结果,因为“gh”是输入的子字符串。我读了很多关于json_contains、json_extract、json_search 甚至json_overlaps 的文章,但无法解决这个问题。
检索相关行的正确 sql 语法是什么?
MySQL 版本为 8.0.20
【问题讨论】: