簡體   English   中英

如何在Bigquery中查詢多個嵌套字段?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM