当前位置: 代码迷 >> Sql Server >> 怎样去除某个字段重复记录?解决方法
  详细解决方案

怎样去除某个字段重复记录?解决方法

热度:8   发布时间:2016-04-27 12:34:29.0
怎样去除某个字段重复记录?
怎样去除某个字段重复记录?表A,有姓名xm,身份证号sfzh,ab,bc等字段,其中相同的身份证号,有很多条数据,因为ab,bc等其它字段不同,现在显示所有数据身份证号sfzh相同的只显示其中一条数据,怎样写这个查询?

------解决方案--------------------
http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
------解决方案--------------------
SQL code
select *from (select *,row_number()over(partition by sfzh order by xm) as row from table1)twhere row=1
------解决方案--------------------
SQL code
select tid=identity(int,1,1),* into # from Aselect xm,sfzh,ab,bc from # t  where not exists(select 1 from # where sfzh=t.sfzh and tid<t.tid)drop table #
------解决方案--------------------
SQL code
表中要有唯一IDdelete from 表where 字段1 in (select 字段1 from 表 group by 字段1 having count(字段1)>1) and ID not in(select min(id) from 表 group by 字段1 having count(字段1)>1)
  相关解决方案