2016-11-10 222 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')