Mysql - JSON_CONTAINS 在数组中查找
Mysql - JSON_CONTAINS find within array
我有 json 列,其中包含以下数据:
[{"option_id": 1, "category_id": 1}, {"option_id": 2, "category_id": 2}]
我正在尝试查找 option_id = 1
的记录
这是我正在尝试的查询:
select count(*) as aggregate from `complaint_forms`
where json_contains(`outcome_options`, '1', '$."option_id"')
计数为 0。我这里做错了什么?
您想将候选人指定为具有所需属性和值的对象,而不仅仅是值,并且不指定路径:
select count(*) as aggregate from `complaint_forms`
where json_contains(`outcome_options`, '{"option_id":1}')
我有 json 列,其中包含以下数据:
[{"option_id": 1, "category_id": 1}, {"option_id": 2, "category_id": 2}]
我正在尝试查找 option_id = 1
的记录这是我正在尝试的查询:
select count(*) as aggregate from `complaint_forms`
where json_contains(`outcome_options`, '1', '$."option_id"')
计数为 0。我这里做错了什么?
您想将候选人指定为具有所需属性和值的对象,而不仅仅是值,并且不指定路径:
select count(*) as aggregate from `complaint_forms`
where json_contains(`outcome_options`, '{"option_id":1}')