Using update with Left Join BigQuery

夙愿已清 提交于 2021-02-11 13:28:12

问题


I am trying to write an Update query with LEFT JOIN in BigQuery but I am not sure how to write it.

  update Table1
  set ColumnTest =  ifnull(b.value, 'no run')
  From left join  (select distinct ID,value FROM Table2 where value = 10) B  --
  where Table1.ID= Table2.ID

I have 2 tables Table1 and Table2

I want to update Table1.ColumnTest with Table2.Value where Table1.ID= Table2.ID and if Table1 <> Table2 then update Table1.ColumnTest with 'no run'

Thanks!!

New Try

  UPDATE Table1
  SET LP = IFNULL(t2.value, 'no run')
  FROM (     select distinct hits.eventInfo.eventCategory as ID, value
       FROM Table2
       CROSS JOIN UNNEST (hits) AS hits
       left join  TAble1 using (hits.eventInfo.eventCategory)
       WHERE) t2
 WHERE t1.ID = t2.ID

Error: Syntax error: Expected ")" or "," but got "."


回答1:


I want to update Table1.ColumnTest with Table2.Value where Table1.ID= Table2.ID and if Table1 <> Table2 then update Table1.ColumnTest with 'no run'

Below is for BigQuery Standard SQL

UPDATE `table1` t1
SET ColumnTest = IFNULL(value, 'no run')
FROM (
  SELECT id, value
  FROM `table1`
  LEFT JOIN `table2`
  USING(id) 
) t2
WHERE t1.id = t2.id


来源:https://stackoverflow.com/questions/63889590/using-update-with-left-join-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!