【发布时间】:2019-11-25 04:27:21
【问题描述】:
我在 mysql 表中有一个列 userinventory 包含以下数据,我想删除其中一个 json 对象,其中 "sellFlag":"y" 和 "product_id":"1"[{
"price": "250",
"category": "Furniture",
"sellFlag": "y",
"assetLink": "Furniture/Table",
"product_id": "1"
},
{
"price": "175",
"category": "Furniture",
"assetLink": "Furniture/IkeaStockholmCoffeeTableBlack",
"product_id": "31"
},
{
"price": "300",
"category": "Furniture",
"assetLink": "Furniture/ZanottaDamaSofaMultiseater",
"product_id": "29"
},
{
"price": "200",
"category": "Furniture",
"assetLink": "Furniture/RoundTable",
"product_id": "9"
}]
我试过select JSON_SEARCH(userInventory,'all','y', NULL,'$[*].sellFlag') as uInvent FROM user_information WHERE user_id=50它的给出结果"$[27].sellFlag",但我也需要为product_id添加条件
成功删除后,需要以下结果。[{
"price": "175",
"category": "Furniture",
"assetLink": "Furniture/IkeaStockholmCoffeeTableBlack",
"product_id": "31"
},
{
"price": "300",
"category": "Furniture",
"assetLink": "Furniture/ZanottaDamaSofaMultiseater",
"product_id": "29"
},
{
"price": "200",
"category": "Furniture",
"assetLink": "Furniture/RoundTable",
"product_id": "9"
}]
【问题讨论】:
-
谁能告诉我如何在 json_search() 中添加两个条件?就像在下面的查询
select JSON_SEARCH(userInventory,'all','y', NULL,'$[*].sellFlag') as uInvent FROM user_information中一样,只搜索“$[*].sellFlag” 我也想为 product_id 添加条件。