当前位置: 代码迷 >> Sql Server >> 求条删除有重复的数据的语句解决办法
  详细解决方案

求条删除有重复的数据的语句解决办法

热度:78   发布时间:2016-04-27 20:45:59.0
求条删除有重复的数据的语句

表1

mobile
10000
10000
20000
30000
30000
40000

我想用语句变成
表1

mobile
10000
20000
30000
40000

------解决方案--------------------
select distinct mobile # into #a from tablename
delete tablename
insert into tablename(mobile)
select mobile from #a
drop table #a
------解决方案--------------------
如果完全一樣只樓上的做法
------解决方案--------------------
delete form 表1 where mobile not in (select mobile from 表1 group by mobile)

或者用distinct mobile
如果只用第一位做判断就把所有的mobile换为left(mobile,1)
  相关解决方案