读书人

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

发布时间: 2012-01-11 22:28:46 作者: rapoo

求条删除有重复的数据的语句

表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)

读书人网 >SQL Server

热点推荐