如何在where子句[BigQuery]中为数组设置条件

问题描述 投票:0回答:1

我的表中有一个数组 - 这样的:

enter image description here

我只需要考虑'top_authors.author'='Caivi'和'top_authors.total_score'= 3的行

我试图使用不需要的函数,但我仍然得到错误“没有匹配的操作符签名=参数类型:ARRAY,STRING。支持的签名:ANY = ANY”

你可以帮助mi吗?

sql google-cloud-platform google-bigquery
1个回答
3
投票

您可以在unnest()子句中的子查询中使用where

where exists (select 1
              from unnest(top_authors) ta
              where ta.author = 'Caivi' and ta.total_score = 3
             )

或者您可以在主查询中执行此操作:

select . . . 
from t cross join
     unnest(top_authors) ta
where ta.author = 'Caivi' and ta.total_score = 3;

假设您没有数组中的重复项,这些应该产生相同的结果。

© www.soinside.com 2019 - 2024. All rights reserved.