我尝试使用"any_value“函数,但它使我一直返回NULL。
下面是我的问题的例子。需要注意的是,它适用于tid字段,但不适用于seller (我确实需要的)。
我不知道为什么会发生这种事。
select
*
, any_value(seller) over (partition by gid) as other_seller
, any_value(tid) over (partition by gid) as other_tid
FROM `my_Table`

发布于 2022-05-10 22:30:29
我不知道为什么会发生这种事。
ANY_VALUE的行为就好像指定了方面NULL;可以考虑并选择表达式为NULL的行。
那么,考虑下面的选项
select
*
, max(seller) over (partition by gid) as other_seller
, max(tid) over (partition by gid) as other_tid
FROM `my_Table` 如果您想将输出随机化,请尝试如下
select
*
, first_value(seller) over (partition by gid order by if(seller is null, 1, rand())) as other_seller
, first_value(tid) over (partition by gid order by if(tid is null, 1, rand())) as other_tid
FROM `my_Table`https://stackoverflow.com/questions/72193445
复制相似问题