Code createtable Table1 ( id intidentity(1,1) primarykey, col1 char(5), col2 datetime, col3 int )
--筛选出重复数据(ID不同,其它列都相同) with a as ( select ROW_NUMBER() over(orderby id desc) as rownumber,Table1.* from Table1 ), b as ( selectmin(rownumber) as minRow from a groupby col1,col2,col3 ) select id,a.*,b.minRow
from a leftouterjoin b on a.rownumber = b.minRow where b.minRow isnull