我有一个有三张桌子的数据库。
1
)134356
)info_u134356_cpn_1
或info_cpn_1_u134356
我需要从user_source中的合并值中划分数据,这样我就可以在一个表格中看到user_id及其关联的广告系列号码,然后计算每个广告系列的用户数量。
我无法理解分裂列的方式,以及是否有办法不进行吐痰(例如以某种方式过滤)。
我目前正在使用DataGrip。
答案 0 :(得分:0)
您可以在Postgres中使用regexp_match()
:
with sample (dump) as (
values
('info_cpn_1_u134356'),
('info_u456789_cpn_5')
)
select (regexp_match(dump, 'u([0-9]+)'))[1] as user_id,
(regexp_match(dump, 'cpn_([0-9]+)'))[1] as campaign
from sample;
返回:
user_id | campaign
--------+---------
134356 | 1
456789 | 5