时间:2021-07-01 10:21:17 帮助过:5人阅读
create table A(ANAME varchar(20)); insert into A values(‘alan‘); insert into A values(‘Alee‘); insert into A values(‘aspn‘); create table B ( BNo varchar(10), BTell varchar(20), Name varchar(20) ); insert into B values(‘NO1‘,‘1366666‘,‘alan‘); insert into B values(‘NO1‘,‘1388888‘,‘alan‘); insert into B values(‘NO1‘,‘1399999‘,‘alan‘); insert into B values(‘NO2‘,‘1333333‘,‘Alee‘); insert into B values(‘NO3‘,‘1311111‘,‘aspn‘); insert into B values(‘NO3‘,‘1322222‘,‘aspn‘);
直接关联查询的话,结果如下
需求是只要每个人的第一条记录(按BTELL排序)
select * from a left join (select * from (select b. *, (row_number() over(partition by bno order by BTell desc)) px from b) e where px = 1) t on a.aname = t.name;
查询结果如下
参考:https://www.cnblogs.com/luxd/p/8527457.html
Oracle-left join两表关联只取B表匹配到的第一条记录
标签:ber arch value creat 必须 image over acl mamicode