T-SQL百万记录中分组取最大值方法ROW_NUMBER() OVER()
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)
查询结果如下图:
posted on 2014-02-11 11:53 loveking_阳 阅读(643) 评论(0) 编辑 收藏 举报