我试图在表格中插入不同的行,但是,标题中出现错误。我不明白的是,我已将LIMIT设置为1,因为我认为这可以解决问题。
有人可以阐明这一点吗?
错误:子查询返回的多于一行用作表达式。
INSERT INTO reports.sem_attribution_v2
SELECT DISTINCT
tsa.user_id,
tsa.transfer_date,
tsa.engine,
tsa.campaign_id,
tsa.adgroup_id,
(CASE
WHEN tsa.engine = 'quora' THEN NULL
WHEN tsa.source ILIKE '%uac%' THEN (
SELECT
account
FROM reports.lookup_uac_elements
WHERE campaign_id = tsa.campaign_id
LIMIT 1)
WHEN tsa.engine = 'google' THEN (
SELECT
pse.account_name
FROM reports.lookup_paid_search_elements pse
WHERE pse.campaign_id = tsa.campaign_id
AND pse.adgroup_id = tsa.adgroup_id
LIMIT 1)
WHEN tsa.engine = 'bing' THEN (
SELECT
lbe.account_name
FROM reports.lookup_bing_elements lbe
WHERE lbe.campaign_id = tsa.campaign_id
AND lbe.adgroup_id = tsa.adgroup_id
LIMIT 1
)
ELSE NULL
END) as account_name,
(
CASE
WHEN tsa.engine = 'quora' THEN NULL
WHEN tsa.source ILIKE '%uac%' THEN (
SELECT
lue.campaign
FROM reports.lookup_uac_elements lue
WHERE lue.campaign_id = tsa.campaign_id
)
WHEN tsa.engine = 'google' THEN (
SELECT
pse.campaign_name
FROM reports.lookup_paid_search_elements pse
WHERE pse.campaign_id = tsa.campaign_id
AND pse.adgroup_id = tsa.adgroup_id
LIMIT 1
)
WHEN tsa.engine = 'bing' THEN (
SELECT
lbe.campaign_name
FROM reports.lookup_bing_elements lbe
WHERE lbe.campaign_id = tsa.campaign_id
AND lbe.adgroup_id = tsa.adgroup_id
LIMIT 1
)
ELSE NULL
END
) as campaign_name,
(CASE
WHEN tsa.engine = 'quora' THEN NULL
WHEN tsa.source ILIKE '%uac%' THEN NULL
WHEN tsa.engine = 'google' THEN (
SELECT
pse.adgroup_name
FROM reports.lookup_paid_search_elements pse
WHERE pse.campaign_id = tsa.campaign_id
AND pse.adgroup_id = tsa.adgroup_id
LIMIT 1
)
WHEN tsa.engine = 'bing' THEN (
SELECT
lbe.adgroup_name
FROM reports.lookup_bing_elements lbe
WHERE lbe.campaign_id = tsa.campaign_id
AND lbe.adgroup_id = tsa.adgroup_id
LIMIT 1
)
ELSE NULL
END) as adgroup_name,
tsa.creation_platform,
tsa.profile_country,
tsa.ltr_12m,
tsa.costs_12m,
tsa.ltv_12m,
tsa.first_paid_touch,
tsa.even_weights,
tsa.first_team_touch,
(CASE
WHEN tsa.profile_type = 'business' THEN 1
ELSE 0
END) as business,
tsa.content,
tsa.ltr_12m_r,
tsa.costs_12m_r,
tsa.ltv_12m_r,
(CASE
WHEN tsa.profile_type = 'consumer' THEN 1
ELSE 0
END) as consumer
FROM tmp_sem_attribution tsa;