在MySQL中根据JSON中的id筛选表

在MySQL中根据JSON中的id筛选表,mysql,arrays,json,Mysql,Arrays,Json,我想从MySQL中的JSON数组中筛选一个表。例如: select description from books where id_of_the_book in (jsonarray) 实际上我试过这个: set @test = JSON_ARRAY(JSON_OBJECT('id','1'),JSON_OBJECT('id','2'),JSON_OBJECT('id','3')); select description from books where id_of_the_book in

我想从MySQL中的JSON数组中筛选一个表。例如:

select description from books where id_of_the_book in (jsonarray)
实际上我试过这个:

set @test = JSON_ARRAY(JSON_OBJECT('id','1'),JSON_OBJECT('id','2'),JSON_OBJECT('id','3'));

select description from books where id_of_the_book in (select JSON_EXTRACT(@test, '$**.id'))

但它不起作用


谢谢

我们开始了,找到了解决方案

drop procedure if exists Sp_ConvertJsonToTable;
create procedure Sp_ConvertJsonToTable()
begin


 declare jsonTest json default JSON_ARRAY(JSON_OBJECT('idcapitolo','1'),JSON_OBJECT('idcapitolo','2'),JSON_OBJECT('idcapitolo','3'));
 declare lunghezzaJson int default json_length(jsonTest);


declare contatore int default 0;


 drop temporary table if exists JsonToTableIds;
    create temporary table JsonToTableIds (
        valoriUtili int
    );




while contatore < lunghezzaJson do

    set @JsonSearch = concat('$[',contatore,'].idcapitolo');
    insert into JsonToTableIds(valoriUtili) values ((select json_unquote(json_extract(jsonTest,@JsonSearch))));
    set contatore = contatore + 1;
    end while;




-- select * from JsonToTableIds;
select descrizionebreve from capitolo where idcapitolo in((select * from JsonToTableIds));
drop temporary table JsonToTableIds;


end;
有两种选择:

使用:

SET@`sql`:=CONCAT' 选择 `id`, `描述` 从…起 `书` 哪里 `id'IN', 选择 代替 代替 JSON_EXTRACT@`JSON`,'$**.id', ']', , '[', , ; 从@sql`中准备'stmt'; 执行'stmt'; 取消分配“stmt”; 使用:

选择 `id`, `描述` 从…起 `书` 哪里 `身份证 选择 `书名` 从…起 JSON_表 @`json`, '$[*]' 柱 `_'BIGINT UNSIGNED PATH'$.id'中的id `德` ;
请参阅。

谢谢,json table one可能是最好的,但我的办公室正在运行mysql5.7。就我而言,如果没有存储过程,stmt one似乎很好!