I have a table that stores Stock as JSON data type.
I need to write a query that returns the ProductID and Quantity in this output format:
However the most close to it I managed to do is this output:
SELECT
GenerationTime
JSON_QUERY_ARRAY(Stock.Sellable) Stock_Sellable_ProductID
,OrganizationUnit.IsDeleted OrganizationUnit_IsDeleted
,OrganizationUnit.Description OrganizationUnit_Description
,OrganizationUnit.BranchNumber
,OrganizationUnit.BranchNumber
FROM
`....xt_...stock`
where GenerationTime = timestamp("2022-08-09 01:00:28.169503 UTC")
I also managed to use UNNEST but this will repeat the GenerationTime four times:
SELECT
GenerationTime
,s.ProductID
,OrganizationUnit.IsDeleted OrganizationUnit_IsDeleted
,OrganizationUnit.Description OrganizationUnit_Description
,OrganizationUnit.BranchNumber
,OrganizationUnit.BranchNumber
FROM
`....xt_...stock`
left join unnest(JSON_QUERY_ARRAY(Stock.Sellable)) s
where GenerationTime = timestamp("2022-08-09 01:00:28.169503 UTC")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.