SQL 左联接去除左边重复的数据
代码如下:
use DB
go
select table1.*,b.OPTime from [dbo].[table1] left join(
select * from (select table2.*,ROW_NUMBER() over(partition by ArchivesID order by OPTime) m from table2 where OPType='档案转出') t1 where m=1) b on table1.ID=b.ArchivesID
where table1.ArchivesStatus='转出' order by b.OPTime desc