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

posted @ 2014-11-12 09:51  情若天_RunUp  阅读(1341)  评论(0编辑  收藏  举报