3つのテーブルから値を選択したい。各テーブルにはbuyer_entity_id列があります。
2つのテーブルで外部結合を行うための構文を思いついたのですが、3番目のテーブルを追加する方法がわかりません。
これが、2つのテーブル結合のステートメントです。これは、私が望むとおりに機能します。
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;
3番目のテーブルには同じselectステートメントがあり、buyer_entity_id値にも結合されます。ただし、3番目のselectステートメントを追加すると、「キーワードがありません」というエラーが発生します。以下は、私の3方向の完全な外部結合ステートメントです。
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;