2016-11-08 155 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.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行的問題,但我不能似乎看到它

+1

您正在使用SQL Server語法一個MySQL標籤。可能會建議切換數據庫。 –

+0

錯誤信息是什麼? – Viki888

+0

可以請您提一下哪種類型的錯誤是 – mansi

回答

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 
+0

優勝者優勝者雞晚餐 – TastyBurgers

0

錯誤的是(有應該是(in)而不是(=)並且始終指定一個表名稱BEST PRACTICE(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 
+0

請不要只做代碼轉儲。 – Drew