sql server 分组获取第一条数据
select temp.* from (
SELECT *,Row_Number() OVER(partition by carRecordId,checkType ORDER BY checkDatetime desc) as rank
FROM InventoryCheck
) temp
where rank = 1
其中 partition by 后为分组依据,允许按照多字段进行分组
sql server 分组获取第一条数据
select temp.* from (
SELECT *,Row_Number() OVER(partition by carRecordId,checkType ORDER BY checkDatetime desc) as rank
FROM InventoryCheck
) temp
where rank = 1
其中 partition by 后为分组依据,允许按照多字段进行分组