【问题标题】:Reading array json - memsql读取数组 json - memsql
【发布时间】:2017-05-15 22:22:21
【问题描述】:

读取数组 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 ??

【问题讨论】:

    标签: json singlestore


    【解决方案1】:

    很遗憾,我们目前不直接支持此功能。

    解决方法是创建一个包含 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2019-10-16
      • 1970-01-01
      • 2011-08-03
      • 2016-12-08
      相关资源
      最近更新 更多