JSON 查询, whereJsonContains 未查询出结果
这是 Laravel 的查询
Model::query()->whereJsonContains('attributes->value_id', [1,3])->count()
得到的 sql 语句
select count(*) as aggregate from `goods_skus` where json_contains(`attributes`->'$."value_id"', '[1,3]');
最后查询的结果: 0
mysql 原声的语句
select count(*) as aggregate from `goods_skus` where json_contains(`attributes`->'$[*]."value_id"', '[1,3]');
这个能查询出来结果: 1
这是我数据库存储的 json
[{"name": "name1", "value": "value1", "name_id": 1, "value_id": 1}, {"name": "name2", "value": "value3", "name_id": 2, "value_id": 3}]
我想问一下这两个 sql 语句有什么区别吗?
Laravel version: 5.7.*
Mysql version: 5.7.23
推荐文章: