急!!!去掉重复记录问题
a b c
-----------------
1 1 a
1 2 b
1 3 c
2 4 d
1 5 e
2 6 f
2 7 g
3 8 h
怎样得到这样的结果:
a b c
-----------------
1 1 a
2 4 d
3 8 h
谢谢!!!
------解决方案--------------------楼主的:
DOC_ID DOC_NAME DOC_ADDR
1 WANG BEIJING
2 ZHANG SHANGHAI
1 SHEN NANJING
1 LIU XIAN
如果没有大小关系,只有处理数据通过新增列,或显示临时表实现...
alter table ta add id int identity(1,1) not null
--查
select * from ta a
where not exists(select 1 from ta where DOC_ID=a.DOC_ID and id <a.id)
--删
delete a
from ta a
where exists(select 1 from ta where DOC_ID=a.DOC_ID and id <a.id)
删除辅助列 alter table ta drop column id