如何根据A表商品编码去匹配B表最新日期的其中一条数据(只需返回B表其中一个字段),怎么样的写法获取数据最快?

如何根据A表商品编码去匹配B表最新日期的其中一条数据(只需返回B表其中一个字段),怎么样的写法获取数据最快?

img

需求:上图所示:根据A表的商品编号去匹配B表相同的商品编号,获取B表其中一条最新日期的价格字段值出来,最终结果显示select *,价格 from A

select * from
(select *,row_number() over(partition by 商品编号 order by 日期 desc) as date_flag from B
where 商品编号 in (select 商品编号 from A)
) as a
where a.date_flag = 1;
select A.*, c.jg
from A
inner join (select b.编号 bh, b.价格 jg
from b
where (b.编号 b.更新时间) in
(select b.编号 bh, b.max(更新时间) updtime
from b
group by b.编号)) c
where a.编号 = c.bh