我想声明变量等于我的'campaign'列中字符串的最后一部分。
我的竞选专栏是这样的:
live_c_account_p_search_ct_dsa_l_location
我想能够提取文本以下l和创建一个新的列,我可以稍后分组。
以下两种方法都可以。
with data as (
select 'a_b_c_d' as campaign union all
select 'x_y_z' union all
select 'live_c_account_p_search_ct_dsa_l_location'
)
select
campaign,
regexp_extract(campaign, '.*_(.*)') as method1,
array_reverse(split(campaign,'_'))[safe_ordinal(1)] as method2
from data