表一
表2
+
我当前查询这个
SELECT *, (SELECT id FROM tb1 where id = 1) as data_json FROM `tb5`
我想在一列中获取表 tb1 的全部数据 像那样
id | col1 | col2 | col3 | col4 | data_json
1 | ab | ab | uo | ty | [{'col1':1, 'col2':'ok', 'col3':'yy'},{'col1':1, 'col2':'ok', 'col3':'yy'}...]
这里告诉我如何改变逻辑
如何从 tb5 获取整个 json 数据我不想使用连接和特定列提及想要整个 tb5
帮帮我......!
最佳答案
我们需要这些 json
函数来转换您的数据。
select t1.*,
json_arrayagg(json_object('col1', t2.col1, 'col2', t2.col1, 'col3', t2.col3)) as data_json
from tb5 t1
inner join tb1 t2 on t2.id = t1.id
where t2.id = 1;
关于mysql - 如何获取选择子查询,其中另一个表的整个数据以json格式获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59281008/