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 後爲分組依據,允許按照多字段進行分組