I've JSON string in Athena as follows:
[{name=agreementUrl, value=agmt-id00001}, {name=sellerOfRecord, value=ABC Corporation}]
[{name=agreementUrl, value=agmt-id00002}, {name=sellerOfRecord, value=XYZ Corporation}]
I'm trying to get the values of Agreement ID in separate columns Agreement ID and sellerOfRecord. With the below query I was able to get these values out but these comes in separate rows. How can I get the agreement ID and corresponding vendor in the same result record?
SELECT
license_metadata.name,license_metadata.value
FROM
json_licensedata
CROSS JOIN UNNEST(licensemetadata) t (license_metadata)
| name | value |
|---|---|
| agreementUrl | agmt-id00001 |
| sellerOfRecord | ABC Corporation |
| agreementUrl | agmt-id00002 |
| sellerOfRecord | XYZ Corporation |
Expected Output:
| Agreement ID | sellerOfRecord |
|---|---|
| agmt-id00001 | ABC Corporation |
| agmt-id00002 | XYZ Corporation |
You can apply the conditional aggregation on the dataset produced by your query :