当前位置: 代码迷 >> Sql Server >> 怎樣根據某些值重復刪除數據庫里記錄?该怎么解决
  详细解决方案

怎樣根據某些值重復刪除數據庫里記錄?该怎么解决

热度:551   发布时间:2016-04-27 16:08:21.0
怎樣根據某些值重復刪除數據庫里記錄?
例如有表A
        a                 b                   c
    6AF                 1                   40
    6AF                 1                   80
    7AE                 2                   50
    7AE                 2                   60

現在把a   ,   b   列重復的刪除只留一筆(哪筆都無所謂)
結果應該是
        a                 b                   c
    6AF                 1                   40
    7AE                 2                   50


------解决方案--------------------
如果有某个字段(不包含A,B)能确定大小就行.
如果不能,必须使用临时表.

1,如果有某个字段能确定打下,如C,按我上述方法.

2,如果没有.使用临时表.
select id=identity(int,1,1) , * into temp from tb
delete temp where id not in (select min(id) from tb group by a,b)
select * from temp
  相关解决方案