您的位置:首页 > 数据库

SQL删除重复数据方法

2011-05-21 23:37 405 查看
例如:

id name value

1 a pp

2 a pp

3 b iii

4 b pp

5 b pp

6 c pp

7 c pp

8 c iii

id是主键

要求得到这样的结果

id name value

1 a pp

3 b iii

4 b pp

6 c pp

8 c iii

方法1

delete YourTable

where [id] not in (

select max([id]) from YourTable

group by (name + value))

方法2

delete a

from 表 a left join(

select id=min(id) from 表 group by name,value

)b on a.id=b.id

where b.id is null

例子

delete dbo.tb_Member_Day_Bonus_Quick_Status_2

where [id] not in (

select max([id]) from tb_Member_Day_Bonus_Quick_Status_2

group by (Member_Code + cast( Layer as nvarchar(100)) ))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: