这应该适用于使用公用表表达式的 SQL Server
create table events (mac nvarchar(3), na nvarchar(3))
insert into events values ('abc',null);
insert into events values ('abc',null);
insert into events values ('def',null);
create table enrichments (mac nvarchar(3), na nvarchar(3), timestamp int)
insert into enrichments values ('abc','na1',1)
insert into enrichments values ('abc','na2',2)
insert into enrichments values ('abc','na3',3)
insert into enrichments values ('def','na4',1)
with latestEnrichment (mac, latestTimestamp) as
(select mac, MAX(timestamp)
from enrichments
group by mac)
update events
set na = en.na
from events e join enrichments en on e.mac = en.mac
join latestEnrichment le on en.timestamp = le.latesttimestamp and
en.mac = le.mac