【问题标题】:filtering array elements from string columns bigquery从字符串列 bigquery 过滤数组元素
【发布时间】:2021-11-11 05:05:08
【问题描述】:

我有两张桌子

第一张桌子

Row  feature_groups           array_words   
1    chat seller              chat
2    product picture/video    product picture
                              video

第二张桌子

Row  events                                       
1    product picture is perfect     
2    video on product babyboy
3    chat bot creation
4    image gorilla

我想根据array_words过滤掉事件

结果应该是 -

Row  events                         feature_groups
1    product picture is perfect     product picture/video
2    video on product babyboy       product picture/video
3    chat bot creation              chat seller

任何有关 biqquery 的帮助都会有很大帮助

【问题讨论】:

  • 你如何假装加入两个表?你有任何匹配两者的 ID 吗?
  • 我可以做交叉连接,没有匹配的 id 列

标签: sql google-cloud-platform google-bigquery


【解决方案1】:

考虑以下方法

select events, feature_groups from (
  select *, 
    (
      select count(1)
      from unnest(split(t2.events, ' ')) word
      join t1.array_words word
      using(word)
    ) match
  from table_2 t2, table_1 t1
  where true
  qualify row_number() over(partition by events order by match desc) = 1
  and match > 0
)     

如果应用于您问题中的样本数据

Table_1

和 Table_2

输出是

【讨论】:

  • 谢谢,解决了
猜你喜欢
  • 2022-01-03
  • 1970-01-01
  • 2020-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多