主键为ID
select * from [infotops] where Id in (select max(id) from [infotops] group by InfoId)
----------------------------------------------------- 巩固----------------------------------------------
group by
PARTITION BY 看图比较区别
SELECT ROW_NUMBER() OVER ( PARTITION BY Infoid order by id desc) rowNum ,
*
FROM [InfoTops] t1 with(nolock) ---》
with infos as
(
SELECT ROW_NUMBER() OVER ( PARTITION BY Infoid order by id desc) rowNum ,
*
FROM [InfoTops] t1 with(nolock)
)
select * from infos where rowNum=1 ---------------》