ID date
-------------------- ----------
1 2015-02-04
2 2015-02-05
3 2015-02-05
4 2015-02-05
5 2015-02-06
6 2015-02-06
想要的结果
ID date
-------------------- ----------
3 2015-02-05
4 2015-02-05
6 2015-02-06
想出 date 有重复的删除掉,有重复的保留ID最小的数据,删除以上的数据,保留以下数据
ID date
-------------------- ----------
1 2015-02-04
2 2015-02-05
5 2015-02-06
------解决思路----------------------
if object_id('a') is not null drop table a
go
create table a(id int identity(1,1),
date datetime)
go
insert into a values('2015-02-04')
insert into a values('2015-02-05')
insert into a values('2015-02-05')
insert into a values('2015-02-05')
insert into a values('2015-02-06')
insert into a values('2015-02-06')
go
delete from a where id not in (select MIN(id) as id from a group by date)
go
select * from a