简体   繁体   English

在 where 子句 Bigquery 中使用聚合函数更新表

[英]Update Table with Aggregate function in where clause Bigquery

I have TableA with the following data我有包含以下数据的 TableA

 Name   A   B   Final
 Andy   1   1   2 
 Sam    1   0   2

I want to write an update query which will do the following:我想编写一个更新查询,它将执行以下操作:

  1. If sum(A+B) <> Final then update row else do not Update如果 sum(A+B) <> Final 则更新行,否则不更新

My Query我的查询

Update TableA
Set A = Case when Final in (1,2) then 1 else 0 End
Set B = Case When Final = 2 then 1 else 0
where final in (1,2) and **final <> sum(A+B)**

Since we can't use an aggregate function in update where clause I am not sure how to do the last part.由于我们不能在 update where 子句中使用聚合函数,所以我不确定如何做最后一部分。

The query should only update row for Sam.查询应该只更新 Sam 的行。

Thanks for you help!谢谢你的帮助!

Update TableA
Set A = Case when Final in (1,2) then 1 else 0 End
Set B = Case When Final = 2 then 1 else 0
where final in (1,2) and final <> A+B

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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