select
temp.id,
temp.orderid,
temp.addtime,
temp.name
from (
select
t.id,
t.orderid,
t.addtime,
t.name,
row_number() OVER(PARTITION BY orderid ORDER BY t.addtime desc) as row_flg
from B t ) temp
where temp.row_flg = '1'
--根据时间取出a表中相同主键的字段最近的,去掉重复的