答案 0 :(得分:4)
您可以使用row_number()
执行此操作,但使用相关子查询通常更有效:
select t.*
from t
where t.exActId = (select max(t2.exActId) from t t2 where t2.carId = t.carId);
答案 1 :(得分:1)
根据Max(ID)
使用分组依据
例如:
Select max(ID),name from TableName group BY ID
答案 2 :(得分:1)
试试这个:
SELECT *
FROM YourTable
WHERE exActId IN (select MAX(exActId) from YourTable GROUP BY CarID);
答案 3 :(得分:1)
SELECT CAR_ID,DRIVER_ID,exActId,contract_id FROM
(
SELECT CAR_ID,DRIVER_ID,exActId,contract_id,ROW_NUMBER() OVER(PARTITION BY CAR_ID,exActId ORDER BY exActId DESC) AS ro_NO FROM TABLE
)
WHERE ro_NO =1