如何解决如何过滤包含数组数据的 BigQuery 数据集?
我有一个包含数组数据的查询。我需要做的是执行可以过滤以下屏幕结果的查询,例如:
“给我带来玩家亚历克斯的数据”。这应该带来 2 行:
1. user1@example.com,2021-01-13 09:32:55.113 UTC,alex,4,[8,10]
2. user1@example.com,2021-01-13 09:30:07.572 UTC,10,[13,14]
如何构造这样的查询?
解决方法
在 BigQuery 的标准 SQL 中尝试以下操作:
with data as (
select "email@email.com" as email,CURRENT_TIMESTAMP() as timestamp,['player1','alex','p3'] as player,[4,4,4] as must_respond_in,['2,9','8,10','7'] as responses
UNION ALL
select "email@email.com" as email,[14,10,14] as must_respond_in,['1,16','13,14','0,0'] as responses
)
select email,timestamp,player[offset(x)],must_respond_in[offset(x)],responses[offset(x)]
from data,unnest(data.player) as player_name with offset x where player_name = 'alex';
我使用 WITH OFFSET
子句来选择我需要的元素。 WITH
子句用于模拟您的数据。
另一种选择
select email,player,must_respond_in,responses
from data t,t.player as player with offset
left join t.must_respond_in as must_respond_in with offset using(offset)
left join t.responses as responses with offset using(offset)
where player = 'alex'
如果适用于您问题中的样本数据 - 输出为
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。