右外连接和内连接使用三个select语句

时间:2017-12-19 17:11:52

标签: sql oracle subquery left-join outer-join

你好我怎么能把拖表作为右外连接和左外连接

select * 
from 
        (select * 
        from 
                ( select 
                        max(challanno) as mc, 
                        itemid 
                from 
                        tablepurchasedetails 
                group by 
                        itemid 
                ) e
        inner join 
                ( select * from tablepurchasedetails 
                ) m on e.mc = m.CHALLANNO and e.itemid=m.itemid 
        )         tab1
right outer join
        (select 
                v_balance.itemid, 
                v_balance.p_total 
        from 
                v_balance 
        group by 
                v_balance.itemid, 
                v_balance.p_total 
        ) x ; on tab1.itemid=x.itemid;

1 个答案:

答案 0 :(得分:0)

你好,你需要一个创建视图作为第一个查询:

 select 
                        max(challanno) as mc, 
                        itemid 
                from 
                        tablepurchasedetails 
                group by 
                        itemid

然后使用视图

加入另一个select语句