读取数组json-memsql

读取数组json-memsql,json,singlestore,Json,Singlestore,读取数组json-memsql 我有一个数组,其中items是json 表: CREATE TABLE `example` ( orderId BIGINT, `data` JSON NULL ); 示例记录 orderId -> ZA/XYZ data -> [ {'item':1,'price':20}, {'item':2,'price':30}, {'item':3,'price':40} (...) ] 当我搜索至少有一个产品大于20的订单时,我使用以下SQL: S

读取数组json-memsql

我有一个数组,其中items是json

表:

CREATE TABLE `example`  (
orderId BIGINT,
`data`  JSON NULL
);
示例记录

orderId -> ZA/XYZ
data -> [
{'item':1,'price':20},
{'item':2,'price':30},
{'item':3,'price':40}
(...)
]
当我搜索至少有一个产品大于20的订单时,我使用以下SQL:

SELECT orderId FROM example WHERE data::`0`::price > 20 OR data::`1`::price > 20 OR data::`2`::price > 20 (...) OR OR OR....
但我不知道订单上有多少产品

这个问题有解决办法吗

也许是这样的:

SELECT orderId FROM example WHERE data::*::price > 20 ??

不幸的是,我们目前并不直接支持这一点

解决方法是创建一个引用表,其中的行包含0、1、2、…:

create reference table r (i bigint primary key);
insert into r values (0), (1), (2), ...;
然后将其合并,并使用每个整数从数组中获取关联值并测试键:

select distinct orderId from example, r where json_extract_double(json_extract_json(data, r.i), 'price') > 20;

不幸的是,我们目前并不直接支持这一点

解决方法是创建一个引用表,其中的行包含0、1、2、…:

create reference table r (i bigint primary key);
insert into r values (0), (1), (2), ...;
然后将其合并,并使用每个整数从数组中获取关联值并测试键:

select distinct orderId from example, r where json_extract_double(json_extract_json(data, r.i), 'price') > 20;