SQL每个用户最后的一条记录
SELECT [ID] ,[UserID] ,[StartDate] ,[EndDate] ,[CreateUser] ,[CreateDate] ,[LastEditUser] ,[LastEditDate] FROM [DB_Base].[dbo].[DB_Contracts] ,(SELECT UserID AS U,MAX(EndDate) AS E FROM dbo.DB_Contracts GROUP BY UserID) temp WHERE temp.U = dbo.DB_Contracts.UserID AND temp.E = dbo.DB_Contracts.EndDate
SQL获取每个用户最后的一条记录
升级版本
SELECT dbo.DB_User.UserNumber , dbo.DB_User.Name , d.StartDate , d.EndDate FROM dbo.DB_User LEFT JOIN ( SELECT [ID] ,[UserID] ,[StartDate] ,[EndDate] ,[CreateUser] ,[CreateDate] ,[LastEditUser] ,[LastEditDate] FROM [DB_Base].[dbo].[DB_Contracts] ,(SELECT UserID AS U,MAX(EndDate) AS E FROM dbo.DB_Contracts GROUP BY UserID) temp WHERE temp.U = dbo.DB_Contracts.UserID AND temp.E = dbo.DB_Contracts.EndDate ) d ON d.UserID = dbo.DB_User.ID WHERE xxxxxxxx