[英]How to query multiple nested fields in Bigquery?
當我查詢兩級嵌套字段時,我錯過了一些行。
模式如下所示:
Productid STRING REQUIRED
Variants RECORD REPEATED
Variants.SKU STRING NULLABLE
Variants.Size STRING NULLABLE
Variants.Prices RECORD REPEATED
Variants.Prices.Country STRING NULLABLE
Variants.Prices.Currency STRING NULLABLE
一些Variants.Prices記錄為空。
當我使用此查詢查詢該表時:
select Productid,Variants.SKU,Variants.Size
from ga-export-0000.feed.feed_dev
,UNNEST (Variants) AS Variants
我得到的行比此行多:
select Productid,Variants.SKU,Variants.Size
,Prices.Currency,Prices.Country
from ga-export-0000.feed.feed_dev
,UNNEST (Variants) AS Variants
,UNNEST(Variants.Prices) as Prices
那是因為它不會返回缺少Variants.Prices的行。
如何修改第二個查詢,以便它返回所有行,如果缺少Variants.Prices,則顯示NULL?
您可能對文檔中的Flattening arrays主題感興趣。 代替逗號,使用LEFT JOIN
,例如:
select Productid,Variants.SKU,Variants.Size
,Prices.Currency,Prices.Country
from `ga-export-0000.feed.feed_dev`
,UNNEST (Variants) AS Variants
LEFT JOIN UNNEST(Variants.Prices) as Prices
如果該數組為空,則將返回NULL
值的Prices
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.