我在下面有这个查询,根据特定条件解析列中的名称。我想扩充此查询以包含一个新行,该行将包含mk_kw表中两列的串联。
insert into mk_kw
with a(v) as (
select "Campaign"
from adwords_raw
), pre as (
select split_part(v, '{', 1) a,split_part(v, '{', 2) b
from a)
select
split_part(a, '-', 1) ca,
split_part(a, '-', 2) cb,
split_part(split_part(a, '-', 3), '|', 1) cc,
split_part(split_part(a, '-', 3),
split_part(split_part(a, '-', 3), '|', 1) || '|', 2) cd,
'{' || b ce
from pre;
当前输入表如下所示,“Campaign”是当前操作列
Campaign |Adgroup |
-----------------------------------+--------+
ES-SRC-IOT|Connectivity|SIM|USA|{e}|Watches |
目前的输出如下所示
ca | cb | cc | cd | ce
----+-----+-----------+----------------------------+------
ES | SRC | IOT | Connectivity | SIM | USA | {e}
我想在此公式中添加一个串联,将其创建为输出
ca|cb |cc |cd |ce |Campaign&AdGroup
---+---+---+--------------------+---+------------------------------
ES|SRC|IOT|Connectivity|SIM|USA|{e}|ES-SRC-IOT|Connectivity|SIM|USA
| | | | |{e}Watches
是否可以添加此连接,还是我必须完全废弃此查询?
干杯。
答案 0 :(得分:0)
试试这个
insert into mk_kw
with a(v,a) as (
select "Campaign","Adgroup"
from adwords_raw
), pre as (
select split_part(v, '{', 1) a,split_part(v, '{', 2) b,v||a as Campaign&AdGroup
from a)
select
split_part(a, '-', 1) ca,
split_part(a, '-', 2) cb,
split_part(split_part(a, '-', 3), '|', 1) cc,
split_part(split_part(a, '-', 3),
split_part(split_part(a, '-', 3), '|', 1) || '|', 2) cd,
'{' || b ce,
Campaign&AdGroup
from pre;
答案 1 :(得分:0)
您不需要使用concat,只需重用现有列:
with a(v,g) as (
select "Campaign","Adgroup"
from adwords_raw
), pre as (
select split_part(v, '{', 1) a,split_part(v, '{', 2) b,v||g "Campaign&AdGroup"
from a
)
select
split_part(a, '-', 1) ca,
split_part(a, '-', 2) cb,
split_part(split_part(a, '-', 3), '|', 1) cc,
split_part(split_part(a, '-', 3),
split_part(split_part(a, '-', 3), '|', 1) || '|', 2) cd,
'{' || b ce,
"Campaign&AdGroup"
from pre;