我想从三个表中选择值。每个表都有一个buyer_entity_id 列。
我想出了在其中两个表上进行外部联接的语法,但是如何添加第三个表却让我望而却步。
这是两个表连接的语句,它完全按照我希望的方式工作:
select * from (select b.buyer_entity_id, count(distinct(a.row_id)) as imps
from imps a, anl_line b
where b.line_item_id=a.buyer_line_id
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab1
full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as clicks
from clicks a, anl_line b
where a.buyer_line_id=b.line_item_id
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab2
on tab1.buyer_entity_id = tab2.buyer_entity_id;
第三个表将具有相同的 select 语句,并且也将连接到 buy_entity_id 值。但是,当我添加第三个选择语句时,我收到“缺少关键字”错误。下面是我的三路全外连接语句:
select * from ((select b.buyer_entity_id, count(distinct(a.row_id)) as imps
from imps_table a, line_table b
where b.line_item_id=a.buyer_line_id
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab1
full outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as clicks
from clicks_table a, line_table b
where a.buyer_line_id=b.line_item_id
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab2)
outer join (select b.buyer_entity_id, count(distinct(a.row_id)) as vers
from vers_table a, line_table b
where b.line_item_id=a.buyer_line_id
and a.entity_id=3
group by b.buyer_entity_id
order by b.buyer_entity_id) tab3
on tab1.buyer_entity_id = tab2.buyer_entity_id and tab2.buyer_entity_id=tab3.buyer_entity_id;