我收到错误:Every derived table must have its own alias
但我没有看到遗漏别名的位置。你能帮我找到吗?
select *
from
(select distinct brand.industry, cur.subindustry, brand.brand, dims.activity, dims.detail, cur.referral_source
from
referraldb.report_referral_db_viz_qa cur
inner join referraldb.report_referral_db_viz_qa prv
on cur.report_time_id = prv.report_time_id
and cur.dimension_id = prv.dimension_id
and cur.brand_id = prv.brand_id
and cur.referral_source = prv.referral_source
and cur.date = date_add(LAST_DAY(DATE_SUB(@d, INTERVAL 1 month)), interval 1 day)
and prv.date = date_add(LAST_DAY(DATE_SUB(@d, INTERVAL 2 month)), interval 1 day)
inner join referraldb.dim_all_dimensions dims
on dims.dimension_id = prv.dimension_id
inner join referraldb.dim_brand brand
on brand.brand_id = prv.brand_id
where
dims.lag = 'immediate'
and dims.measure_type = 'visits'
and prv.subindustry = 'flight'
and prv.report_time_id = 1
and abs((((cur.current_test - prv.current_test)/cur.current_test) * 100)) >= 30)) a
inner join
(select fact.referral_source, brand.Industry, fact.subindustry, brand.Brand, dims.Activity, dims.Detail
from
referraldb.report_referral_db_viz_qa fact inner join
referraldb.dim_brand brand
on brand.brand_id = fact.brand_id inner join
referraldb.dim_report_time t
on t.report_time_id = fact.report_time_id inner join
referraldb.dim_all_dimensions dims
on dims.dimension_id = fact.dimension_id
where dims.lag = 'Immediate' and dims.measure_type = 'Visits' and fact.subindustry = 'flight' and fact.report_time_id = 1 and fact.date > DATE_SUB(NOW(), INTERVAL 14 month)
group by fact.referral_source, brand.Industry, fact.Subindustry, brand.Brand, dims.Activity, dims.Detail
having avg(current_test) > 200000 ) as b
on a.industry = b.industry and a.subindustry = b.subindustry and a.brand = b.brand and a.activity = b.activity and a.detail = b.detail and a.referral_source = b.referral_source
答案 0 :(得分:1)
不应该这一行
having avg(current_test) > 200000 ) as b
是
having avg(current_test) > 200000 ) b
还有一个关闭括号太多(或开口太少)。第一个匹配此行中最后一个之前的那个:
and abs((((cur.current_test - prv.current_test)/cur.current_test) * 100)) >= 30)) a
答案 1 :(得分:1)
首先计算括号。
你有15个开放的parens和16个关闭的parens。