0

您好需要从数组中提取数据,我使用 Athena

create external table test
(
customer string
)
Location 'something-something'

该表的单行是,

select * from customer limit 1

{ "ID": "XXXX", "USerDate": { "items": [{ "Name": "Nir", "CLG": "NPT", "Place": "CBE", "Any Group": {}, "Interest": { "items": [{ "Games": "Cricket", "Music": "AR" }] }, "Others": {} }] } }

我需要像这样提取行

| 身份证 | 姓名 | 地点 | 游戏| 音乐 |

|-----|---------|----------|----------|---------- |

4

1 回答 1

0
select  json_extract_scalar(customer,'$.ID')    as ID
       ,json_extract_scalar(i1.item,'$.Name')   as Name
       ,json_extract_scalar(i1.item,'$.Place')  as Place
       ,json_extract_scalar(i2.item,'$.Games')  as Games
       ,json_extract_scalar(i2.item,'$.Music')  as Music

from    test

        cross join unnest (cast(json_extract(customer,'$.USerDate.items') 
            as array(json))) as i1 (item)

        cross join unnest (cast(json_extract(i1.item,'$.Interest.items')
            as array(json))) as i2 (item)
;

  ID  | Name | Place |  Games  | Music
------+------+-------+---------+-------
 XXXX | Nir  | CBE   | Cricket | AR
于 2017-03-19T11:10:08.613 回答