简体   繁体   English

如何将数据转换成给定的格式?

[英]How to convert data into given format?

task_id     json_data
task1       [ [160, "4d3a339c-68ba"], [15, "554fc01c-b5d2"] ]

I have to change the above image into the below format:我必须将上面的图像更改为以下格式:

task_id     area        iiid    
task1       160         "4d3a339c-68ba"
task1        15         "554fc01c-b5d2"

You can turn the json content to an array of arrays, then unnest it, and then bring the first and second element of each sub-array:可以将json内容转成数组的数组,然后解嵌套,然后带上每个子数组的第一个和第二个元素:

select t.task_id, x.ar[0] area, x.ar[1] iiid
from mytable t
cross join unnest(cast(t.json_data as array(array(varchar)))) as x(ar)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM