日期:2014-05-17 浏览次数:20424 次
select * from a where ax in (select ax from a group by ax having count(ax) > 1)
------解决方案--------------------
--保留一条(这个应该是大多数人所需要的 ^_^) Delete a Where ID Not In (Select Max(ID) From a Group By Title)
------解决方案--------------------
declare @t table(id int);
insert into @t
select 1 union all
select 2 union all
select 3 union all
select 2 union all
select 1
;with c1 as
(
select row_number() over(partition by id order by id) rowid,
id
from @t
)
delete from c1 where rowid > 1
select * from @t order by id
id
-----------
1
2
3
(3 行受影响)
------解决方案--------------------
用distinct 最简单了。不过显示最新插入的也行,
select id,f1,f2 from t tt
where tt.id=
(select max(id)
from t
where tt.f1=t.f1 and tt.f2=t.f2)