首页 > 解决方案 > 如何从SQL中的字符串中提取项目列表

问题描述

我想将 itemid 拆分为一个列表,因为我想将该列表用作另一个查询中的条件:

data
--------------------------------------------------------------------------------
[{"shopid":64522541,"itemid":1260324852},{"shopid":31863766,"itemid":1265550228}]

我试过这样的 JSON_EXTRACT:

SELECT JSON_EXTRACT(data,'$.itemid') from table
WHERE collection_id = 88888

但它不起作用。您能否提供一种方法来提取我可以在以下代码中使用的列表:

Select id in table2 
where id in LIST

标签: mysqljson

解决方案


对于以下查询的 postgrey 可能会有所帮助

  select  (d->>'itemid')::numeric itemid
        from 
         json_array_elements(data::json) d

推荐阅读