【问题标题】:Joining 2 Tables where one is a specific column and the other is a string?连接 2 个表,其中一个是特定列,另一个是字符串?
【发布时间】:2021-10-06 14:53:08
【问题描述】:

我昨天问了这个问题,但我想我需要澄清一些事情。在这里感谢大家的帮助!

基本上,我的目标是通过“中间表”连接 2 个表,其中一个表的共享值位于描述列中,该列是一堆文本。


如果我有 SportsTable 和 player_column 然后有 NewsTable 和 description_column 但其中包含球员姓名...

所以 SportsTable 与 player_column 与“Lebron James” 与 NewsTable 与 description_column 为“比赛中的头号得分手是 Lebron James”。

我可以加入这两个吗?

我收到的回复是针对 LIKE CONCAT 中的特定名称(“Lebron James”),但我希望获得所有出现在 SportsTable 中的球员姓名strong>(如“Lebron James”、“Michael Jordan”等)出现在 NewsTable 的描述字符串列中。

这可能吗?

【问题讨论】:

标签: sql google-bigquery


【解决方案1】:

考虑以下几点:

with SportsTable as (
    select 'Lebron James' as player_column  union all 
    select 'Tom Brady'  union all 
    select 'Michael Jordan'
),
NewsTable as (
    select 'I love Lebron James' as description_column  union all 
    select 'Tom Brady is the GOAT'  union all 
    select 'Lebron James and Michael Jordan are good at basketball'
)
select
    description_column,
    player_column
from SportsTable 
cross join NewsTable
where description_column like concat('%',player_column,'%')
order by 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 2012-11-23
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多