gpt4 book ai didi

mysql - 如何从 mysql json 对象数组中获取特定项目记录

转载 作者:行者123 更新时间:2023-11-29 16:30:34 27 4
gpt4 key购买 nike

尝试以下查询:

select
`prodname`,
parent_cat_id,
sub_cat_id,
color,
JSON_EXTRACT(`product_items`, '$[*].quantity') AS 'qty',
JSON_EXTRACT(`product_items`, '$[*].offerprice') AS 'price'
from
product_details
where
prodid=11 AND
JSON_CONTAINS(product_items, '{"size": "S"}');

在列表中给出数组,以下是我的表结构:

CREATE TABLE `product_details` (
`prodid` int(11) AUTO_INCREMENT NOT NULL,
`prodname` varchar(255) UNIQUE NOT NULL,
`color` varchar(25) NOT NULL,
`product_items` JSON,
`attributelist` JSON,
PRIMARY KEY(prodid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

最佳答案

Set Json Data in Dictionary and then Append this "Data Dictionary" in Array of type Dictionary.Like 
DataDictionary["Column name"] = "Value"
DataArray.Append(DataDictionary)
Now You can get Any item.like
DataArray[indexnum]."Select item that you want by giving Key"

关于mysql - 如何从 mysql json 对象数组中获取特定项目记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53956507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com