狐的传说
如果添加主键不是一种选择,则一种方法是将重复的DISTINCT存储在临时表中,从现有表中删除所有重复的记录,然后将记录从临时表中添加回原始表中。例如(为SQL Server 2008编写的,但是该技术对于任何数据库都是相同的):DECLARE @original AS TABLE([hash] varchar(20), [d] float)INSERT INTO @original VALUES('A', 1)INSERT INTO @original VALUES('A', 2)INSERT INTO @original VALUES('A', 1)INSERT INTO @original VALUES('B', 1)INSERT INTO @original VALUES('C', 1)INSERT INTO @original VALUES('C', 1)DECLARE @temp AS TABLE([hash] varchar(20), [d] float)INSERT INTO @tempSELECT [hash], [d] FROM @original GROUP BY [hash], [d]HAVING COUNT(*) > 1DELETE OFROM @original OJOIN @temp T ON T.[hash] = O.[hash] AND T.[d] = O.[d]INSERT INTO @originalSELECT [hash], [d] FROM @tempSELECT * FROM @original我不确定sqlite是否具有ROW_NUMBER()类型函数,但是如果这样做,您还可以尝试此处列出的一些方法:从没有主键的SQL表中删除重复的记录