列不能外部连接到子查询

create table A(
 
    id number primary key,
 
    act varchar2(100)
 
);
 
create table B(
 
    id number,
 
    actn_numb integer,
 
    primary key(id,actn_numb)
 
);

 
insert into A(id,act) values(1,'art');
 
insert into A(id,act) values(2,'music');
 
insert into A(id,act) values(3,'sport');
 
insert into B(id,actn_numb) values(1,1);
 
insert into B(id,actn_numb) values(1,2);
 
insert into B(id,actn_numb) values(1,3);
 
insert into B(id,actn_numb) values(1,4);
 
insert into B(id,actn_numb) values(1,5);
 
insert into B(id,actn_numb) values(2,1);
 
insert into B(id,actn_numb) values(2,2);
 
insert into B(id,actn_numb) values(2,3);
 
insert into B(id,actn_numb) values(3,1);


select * from A;

select * from B;



    --列不能外部连接到子查询
    select A.*, B.*
      from A
      left join B
        on A.id = B.id
       and B.actn_numb = (select max(B.actn_numb) from B where B.id = a.id);
       --解决办法
       select A.*,C.ACTN_NUMB from A 
    left join (
    select * from (
        select B.*,(row_number() over(partition by id order by actn_numb desc)) rn 
        from B)
        where rn=1 ) C 
    on (C.id=A.id);
    
    --
    select * from a;
    select * from b;
    
    select *
      from a
      left join (select b.* from b where b.actn_numb = 1) c
        on a.id = c.id;

 

转载于:https://www.cnblogs.com/zzzzw/p/10418183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值