我有一个类似于以下的表:
CREATE TABLE `foo` (
`foo_id` bigint(20) NOT NULL AUTO_INCREMENT,
`data` json DEFAULT NULL,
`data_type` int(11) NOT NULL,
`data_status` int(11) NOT NULL,
PRIMARY KEY (`foo_id`)
);
插入一些数据
insert into foo(data, data_type, data_status) values ('{\"id\": \"FOO\", \"code\": \"FOO\"}', 1, 1);
insert into foo(data, data_type, data_status) values ('{\"id\": \"BAR\", \"code\": \"BAR\"}', 1, 1);
insert into foo(data, data_type, data_status) values ('{\"id\": \"BAZ\", \"code\": \"BAZ\"}', 1, 1);
显示表格内容:
mysql> select * from foo;
+--------+------------------------------+-----------+-------------+
| foo_id | data | data_type | data_status |
+--------+------------------------------+-----------+-------------+
| 1 | {"id": "FOO", "code": "FOO"} | 1 | 1 |
| 2 | {"id": "BAR", "code": "BAR"} | 1 | 1 |
| 3 | {"id": "BAZ", "code": "BAZ"} | 1 | 1 |
+--------+------------------------------+-----------+-------------+
3 rows in set (0.01 sec)
此查询有效:
select f.data, f.data_type, f.data_status
from foo f
where (JSON_EXTRACT(f.data, '$.code') in ('FOO'))
and (f.data_type in (1))
and (f.data_status in (1));
+------------------------------+-----------+-------------+
| data | data_type | data_status |
+------------------------------+-----------+-------------+
| {"id": "FOO", "code": "FOO"} | 1 | 1 |
+------------------------------+-----------+-------------+
1 row in set (0.00 sec)
这个也是:
select f.data, f.data_type, f.data_status
from foo f
where (JSON_EXTRACT(f.data, '$.code') in ('BAR'))
and (f.data_type in (1))
and (f.data_status in (1));
+------------------------------+-----------+-------------+
| data | data_type | data_status |
+------------------------------+-----------+-------------+
| {"id": "BAR", "code": "BAR"} | 1 | 1 |
+------------------------------+-----------+-------------+
不过这个不...
select f.data, f.data_type, f.data_status
from foo f
where (JSON_EXTRACT(f.data, '$.code') in ('FOO','BAR'))
and (f.data_type in (1))
and (f.data_status in (1));
Empty set, 1 warning (0.00 sec)
如何使第三个查询起作用?