简体   繁体   中英

UNNEST and JOIN | Big Query

I'm able to unnest one table in Big Query by using the following code:

SELECT * EXCEPT(instance, line_items) FROM (
SELECT *, ROW_NUMBER() OVER(PARTITION BY id) AS instance
  FROM `shopify.orders`
), UNNEST(line_items) as item

WHERE instance = 1

Additionally, I'm able to JOIN this table (unnested) with another table using the following code:

SELECT * FROM (
  SELECT *, ROW_NUMBER() OVER(PARTITION BY id) AS instance
  FROM `shopify.orders`
  JOIN `google_analytics.GA`
  ON name = TransactionID

)

WHERE instance = 1

However, I'm not sure how to JOIN these two tables while still unnesting the values from my first query. Any idea of how I can join an UNNESTED table with another table?

Doesn't join work?

SELECT * EXCEPT(instance, line_items)
FROM (SELECT *, ROW_NUMBER() OVER(PARTITION BY id) AS instance
      FROM `shopify.orders`
     ) o CROSS JOIN
     UNNEST(o.line_items) as item JOIN
     `google_analytics.GA` ga
      ON name = TransactionID

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM