1

我有一张名为ComplimentTransactAssign_tbl. 在这个表中有很多重复的条目。表结构是这样的:

TransactID           Cmplid     
-
32                      16          
105                     17          
105                     17        
290                     12         
32                      16
290                     12

我发现我的重复记录是这样的:

select TransactID  from ComplimentTransactAssign_tbl
  group by TransactID having count(*) >1 order by TransactID

我想删除重复的记录。删除后我想得到这样的输出:

TransactID           Cmplid     
-
32                      16          
105                     17                 
290                     12         
4

1 回答 1

2
;WITH MyCTE AS
(
    SELECT TransactID ,
           Cmplid,
           ROW_NUMBER() OVER(PARTITION BY TransactID ORDER BY TransactID) AS row_num
    FROM ComplimentTransactAssign_tbl cta
)   
DELETE FROM MyCTE 
WHERE row_num <> 1

SQL 小提琴示例

于 2013-09-11T07:25:21.150 回答