SQL 如下
找状态=1的数据,按 HospitalId,DeptId 组合并倒序排序,每组里面取第一条数据
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY HospitalId, DeptId ORDER BY CreateDate DESC ) AS new_index FROM HospitalInfo WHERE Status = 1 ) t WHERE t.new_index = 1;
标签:DeptId,PARTITION,第一条,SELECT,SQL,数据,后取 From: https://www.cnblogs.com/vipsoft/p/16744055.html