declare @tb1 table([name] varchar(10),sn varchar(10)) insert into @tb1 select 'AB', '123' union all select 'AB', '456' union all select 'AB', '456' union all select 'AC', '789' union all select 'AD', '789'select [name],sn=max(sn) from @tb1 group by [name]/* name sn ---------- ---------- AB 456 AC 789 AD 789(所影响的行数为 3 行) */
insert into @tb1
select 'AB', '123' union all
select 'AB', '456' union all
select 'AB', '456' union all
select 'AC', '789' union all
select 'AD', '789'select [name],sn=max(sn) from @tb1 group by [name]/*
name sn
---------- ----------
AB 456
AC 789
AD 789(所影响的行数为 3 行)
*/