inner join 用法

来源:互联网 发布:c语言0到9产生随机数 编辑:程序博客网 时间:2024/06/07 03:31

1.  简单

select * from (
(select * from tb_trade_9740 where f9740_005v='zhoudeling' and f9740_015n=1)

)tab1
inner join
(select * from tb_trade_0022@p1 ) tab2
on tab1.f9740_010v = tab2.f0022_002v




2.复杂

select
tab_1.f9740_010v,
tab_1.f9740_012n,
tab_1.F9740_014N,
tab_2.F0004_007N,
F0045_007N,
(decode(tab_2.F0004_007N,0,F0045_007N,tab_2.F0004_007N)-tab_1.f9740_012n)*tab_1.F9740_014N
 from
(select * from tb_trade_9740 where f9740_005v='heiddy' and f9740_015n=1 and trunc(f9740_001d)=to_date('2011-8-30','yyyy-mm-dd'))
tab_1
inner join
(

select
f0004_001d,
f0004_002v,
F0004_005V,
F0004_007N from tb_ori_0004 where f0004_001d = to_date('2011-8-31','yyyy-mm-dd')   and   f0004_002v =(select max(f0004_002v) from tb_ori_0004 where f0004_001d = to_date('2011-8-31','yyyy-mm-dd'))

)tab_2
on tab_1.f9740_010v=tab_2.F0004_005V
inner join
(
select *
  from (select F0045_001D,
               F0045_002V,
               F0045_003V,
               F0045_004V,
               F0045_007N,
               row_number() over(partition by F0045_004V order by F0045_001D desc) rn
          from tb_trade_0045
         where f0045_001d >= trunc(sysdate) - 20
           and f0045_012n > 0)
 where rn = 1
) tab_3
on tab_1.f9740_010v=tab_3.F0045_004V


原创粉丝点击