首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大查询- ANY_VALUE返回空

大查询- ANY_VALUE返回空
EN

Stack Overflow用户
提问于 2022-05-10 22:11:58
回答 1查看 108关注 0票数 1

我尝试使用"any_value“函数,但它使我一直返回NULL。

下面是我的问题的例子。需要注意的是,它适用于tid字段,但不适用于seller (我确实需要的)。

我不知道为什么会发生这种事。

代码语言:javascript
复制
select 
  *
  , any_value(seller) over (partition by gid) as other_seller
  , any_value(tid) over (partition by gid) as other_tid

FROM `my_Table`

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-10 22:30:29

我不知道为什么会发生这种事。

ANY_VALUE的行为就好像指定了方面NULL;可以考虑并选择表达式为NULL的行。

那么,考虑下面的选项

代码语言:javascript
复制
select 
  *
  , max(seller) over (partition by gid) as other_seller
  , max(tid) over (partition by gid) as other_tid

FROM `my_Table`             

如果您想将输出随机化,请尝试如下

代码语言:javascript
复制
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`
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72193445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档