2014-05-12 130 views
0

我想在oracle中加入2個SQL查詢,但我真的不熟悉它,我的結構似乎對我來說是正確的,但是我有這個SQL錯誤信息: 「[錯誤] ORA-00933:SQL命令不能正確地結束」oracle,查詢加入問題「SQL命令沒有正確結束」

所以我有兩個疑問: 第一個是:

select 
    campaign_id, count(*) as "number of emails sent" 
from 
    dg_res_sent 
where 
    dg_end_date > sysdate 
group by campaign_id 

,第二個是:

select 
    offer_name, 
    campaign_id, 
    offer_category as "link category", 
    count(*) as "number of clicks" 
from 
    dg_res_click 
where 
    dg_end_date > sysdate 
and 
    SUBSTR(offer_name,1,3) = 'SKU' 
group by 
    offer_name, 
    campaign_id, 
    offer_category 

我想做我的加入在CAMPAIGN_ID所以我做:

select 
    offer_name, 
    campaign_id, 
    offer_category as "link category", 
    count(*) as "number of clicks", 
    sent.nb_sent 
from 
    dg_res_click 
where 
    dg_end_date > sysdate 
and 
    SUBSTR(offer_name,1,3) = 'SKU' 
inner join 
    (select 
     campaign_id, count(*) as "nb_sent" 
    from 
     dg_res_sent 
    where 
     dg_end_date > sysdate 
    group by campaign_id) sent 
on 
    sent.campaign_id = dg_res_click.campaign_id 
group by 
    offer_name, 
    campaign_id, 
    offer_category 

任何想法,爲什麼我得到這個消息:

[ERR] ORA-00933:SQL命令不能正確地結束

+1

不應該在where子句之前放置內連接嗎? – Ehsan

+0

我刪除了MySQL和SQL Server標記,因爲這個問題是關於Oracle的。 –

回答

2

你已經把inner join在應該在where條款之前

select 
    dg_res_click.offer_name, 
    dg_res_click.campaign_id, 
    dg_res_click.offer_category as "link category", 
    count(*) as "number of clicks", 
    sent.nb_sent 
from 
    dg_res_click 
inner join 
    (select 
     campaign_id, count(*) as nb_sent 
    from 
     dg_res_sent 
    where 
     dg_end_date > sysdate 
    group by campaign_id) sent 
on 
    sent.campaign_id = dg_res_click.campaign_id 

where 
    dg_res_click .dg_end_date > sysdate 
and 
    SUBSTR(dg_res_click.offer_name,1,3) = 'SKU' 
group by 
    dg_res_click.offer_name, 
    dg_res_click.campaign_id, 
    dg_res_click.offer_category, 
    sent.nb_sent 
+0

謝謝,這對我來說似乎是正確的,但我有這個錯誤信息:「」發送「。」NB_SENT「:無效標識符」 – user2461031

+0

刪除查詢中的引號,然後再試。 –

+0

但它不會是一個字符串不是嗎? – user2461031

2

你的內連接應放在你的where子句之前。

相關問題