[英]Check if value exists in group and assign it to all rows of group in BigQuery
I would like to check if the value a
exists in each user id group and then assign this value to all rows of this user id/group.我想检查每个用户 ID 组中是否存在值
a
,然后将此值分配给该用户 ID/组的所有行。 For example for the following data:例如对于以下数据:
user_id type
123 a
123 b
234 c
I should get:我应该得到:
user_id type
123 a
123 a
234 c
You can achieve this by executing a query similar to this:您可以通过执行与此类似的查询来实现此目的:
UPDATE so_test.a_updates
SET type = 'a'
where user_id in (
select user_id
from `elzagales.so_test.a_updates`
where type = 'a'
);
additionally if this is something you want to repeatedly do you can make this a stored procedure using a similar structure.此外,如果这是您想要重复执行的操作,您可以使用类似的结构将其设为存储过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.