我想在oracle中加入2个SQL查询,但我真的不熟悉它,我的结构对我来说似乎是对的,但是我有这个SQL错误信息:" [Err] ORA- 00933: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命令未正确结束
答案 0 :(得分: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
答案 1 :(得分:2)
您的内部联接应放在where子句之前。