SELECT SysUserID, UserID, ROW_NUMBER() OVER(PARTITION BY UserID ORDER BY AddTime DESC) AS nums FROM dbo.AssignHistoryLog WHERE AssignType = 2 AND SysUserID IN (SELECT userid FROM jdrcadmin.admin WHERE deptId IN (17,18,57,80,33) AND isValid=1)
查询结果如下图: