将更新与左联接和交叉联接 BigQuery 结合使用

Using update with Left Join and cross join BigQuery

我有一个关于我已经发布的问题的后续问题。

我正在尝试实现相同的结果,但也在其中添加了 Cross Join。

   update Table1
   set ColumnTest =  ifnull(b.value, 'no run')
   From left join  
   (select distinct h.eventinfo.eventcategory as ID,value 
   FROM Table2 
   cross join (hits)h )
    where Table1.ID= Table2.ID

我有 2 个表 Table1 和 Table2

我想用 Table2.Value

更新 Table1.ColumnTest

其中 Table1.ID= Table2.hits.eventInfo.eventCategory(取消嵌套表 2)

如果 Table1.ID <> Table2.hits.eventInfo.eventCategory 则更新 Table1.ColumnTest 为 'no run'

谢谢你的帮助!!

试试下面

UPDATE `table1` t1
SET ColumnTest = IFNULL(t2.value, 'no run')
FROM (
  SELECT id, value
  FROM `table1` 
  LEFT JOIN (
    SELECT hit.eventInfo.eventCategory AS id, value
    FROM `table2`
    CROSS JOIN UNNEST (hits) AS hit
  )
  USING(id)
) t2
WHERE t1.ID = t2.ID