0
我使用滞后函数将两个表连接在一起,以便第一个表不显示重复的度量行。使用LAG并比较列
但是,我在预先选择连接时遇到了引用滞后列的问题。
我的查询如下,提到的列标有!!!
select "Campaign",
"Ad group" ,
"Final URL" ,
"Headline 1" ,
"Headline 2" ,
"Description" ,
"Path 1" ,
"Path 2" ,
"Status" ,
"Labels" ,
case when prev_key is null or prev_key != "Key" then "Clicks" end as
"Clicks",
case when prev_key is null or prev_key != "Key" then "Impressions" end
as
"Impressions",
case when prev_key is null or prev_key != "Key" then "Cost" end as
"Cost",
case when prev_key is null or prev_key != "Key" then "Avg. position" end
as
"Avg. position",
case when prev_key is null or prev_key != "Key" then "Initial Leads" end
as
"Initial Leads",
case when prev_key is null or prev_key != "Key" then "Evaluations" end
as
"Evaluations",
case when prev_key is null or prev_key != "Key" then "Won Leads" end as
"Won Leads",
case when prev_key is null or prev_key != "Key" then "Opportunities" end
as
"Opportunities",
"Language",
"Network",
"Main Keyword",
"Cluster Keyword 1",
"Match Type"
from
(SELECT
"x"."Campaign",
"x"."Ad group",
"x"."Final URL",
"x"."Headline 1",
"x"."Headline 2",
"x"."Description",
"x"."Path 1",
"x"."Path 2",
"x"."Status",
"x"."Labels",
!!!lag ("x"."Key") over() AS prev_Key!!!,
"x"."Clicks",
"x"."Impressions",
"x"."Cost",
"x"."Avg. position",
"x"."Initial Leads",
"x"."Evaluations",
"x"."Won Leads",
"x"."Opportunities",
"x"."Language",
"x"."Network",
"x"."Main Keyword",
"x"."Cluster Keyword 1",
"x"."Match Type"
FROM ad_copies_final_joined_concatenated x join
ad_copies_final_to_join_concatenated
using ("Key")
order by "Campaign" desc, "Key"
) sub ;
输出错误信息如下;
ERROR: column "Key" does not exist LINE 11: case when prev_key is null or prev_key != "Key" then "Cli... ^