我正在尝试编写一个查询来提取电子邮件的客户数据。这是查询:
select
opp.*
from
(
select
opp.*,
row_number() over (partition by opp.contact_email_address order by opp.status_date desc) as row_number
from
opportunity_data opp
where
opp.site = 'wesellinsurance'
and opp.email_bounced = 'false'
and opp.email_unsubscribed = 'false'
and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
and opp.latest_mkt_medium not in ('partner','inbound_outbound')
and opp.on_cover = 'false'
and opp.primary_group in ('market_trader', 'food_stand', 'mobile_food_van', 'caterer')
and opp.opportunity_status = ('quote_recieved','rfq_submitted', 'policy_expired_not_renewed')
and datediff(day, cast(latest_rfq_submitted_date as date),cast(getdate() as date)) > 30
and opp.lifecycle = 'new_business'
) opp
where row_number = 1
大多数语法分析师都认为第7行存在问题,但我似乎无法看到它
答案 0 :(得分:1)
第18行缺少
select
opp.*
from
(
select
opp.*,
row_number() over (partition by opp.contact_email_address order by opp.status_date desc) as row_number
from
opportunity_data opp
where
opp.site = 'wesellinsurance'
and opp.email_bounced = 'false'
and opp.email_unsubscribed = 'false'
and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
and opp.latest_mkt_medium not in ('partner','inbound_outbound')
and opp.on_cover = 'false'
and opp.primary_group in ('market_trader', 'food_stand', 'mobile_food_van', 'caterer')
and opp.opportunity_status in ('quote_recieved','rfq_submitted', 'policy_expired_not_renewed')
--------------^
and datediff(day, cast(latest_rfq_submitted_date as date),cast(getdate() as date)) > 30
and opp.lifecycle = 'new_business'
) opp
where row_number = 1
答案 1 :(得分:0)
错误是(应该有(in)而不是(=)并且总是指定一个表名BEST EXACTICE(opp1.row_number))
select
opp1.*
from
(
select
opp.*,
row_number() over (partition by opp.contact_email_address order by opp.status_date desc) as row_number
from
opportunity_data opp
where
opp.site = 'wesellinsurance'
and opp.email_bounced = 'false'
and opp.email_unsubscribed = 'false'
and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
and opp.latest_mkt_medium not in ('partner','inbound_outbound')
and opp.on_cover = 'false'
and opp.primary_group in ('market_trader', 'food_stand', 'mobile_food_van', 'caterer')
and opp.opportunity_status in ('quote_recieved','rfq_submitted', 'policy_expired_not_renewed')
and datediff(day, cast(latest_rfq_submitted_date as date),cast(getdate() as date)) > 30
and opp.lifecycle = 'new_business'
) opp1
where opp1.row_number = 1