2016-11-10 218 views
0

即时消息我为一个广告系列撰写查询,并且每当我尝试运行它时,我都会收到一个错误,指出语法不正确。如何解决“附近的语法错误”,“”?

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.email_bounced = 'false' 
     and opp.email_unsubscribe = 'false' 
     and opp.first_mkt_medium not in ('partner', 'inbound_outbound') 
     and opp.latest_mkt_medium not in ('partner', 'inbound_outbound') 
     and datediff (day, cast(latest_rfq_submitted_date as date), cast(getdate() as date)) > 30 
     and opp.on_cover = 'no' 
     and opp.primary_group in ('Market_trader', 'Food_stand', 'Mobile_food_van', 'Caterer') 
     and opp.site = 'simplybusiness' 
     and opp.opportunity_status = ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed') 
) opp 
where row_number = 1 
+0

删除一些代码,重试,删除一些更多的代码,重试等 – jarlh

+0

请添加完整的错误消息。 –

+0

欢迎来到Stack Overflow!为了帮助人们回答您的问题,您需要更加具体地了解错误。请编辑您的帖子,以便将编译[mcve]时的确切错误(最好使用复制+粘贴以避免转录错误)。 –

回答

1

检查与此:

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.email_bounced = 'false' 
     and opp.email_unsubscribe = 'false' 
     and opp.first_mkt_medium not in ('partner', 'inbound_outbound') 
     and opp.latest_mkt_medium not in ('partner', 'inbound_outbound') 
     and datediff (day, cast(latest_rfq_submitted_date as date), cast(getdate() as date)) > 30 
     and opp.on_cover = 'no' 
     and opp.primary_group in ('Market_trader', 'Food_stand', 'Mobile_food_van', 'Caterer') 
     and opp.site = 'simplybusiness' 
     and opp.opportunity_status in ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed') 
) opp 
where row_number = 1 
+0

我们有一个winrar – TastyBurgers

1

该错误出现是因为您的上一条where行。你不能像这样使用它。我想你想使用in,而不是=

AND opp.opportunity_status IN ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed')