删除重复的条目,如果id列不可用,则保留每个条目的一个条目

时间:2017-08-21 09:35:38

标签: sql sql-server

我试过了,

delete from Student where FirstName in
(
    select FirstName  from
    (
     select FirstName,
     row_number() over(partition by FirstName order by FirstName) as rn
     from Student
    ) Student
    WHERE rn > 1
);

但它删除了两个重复的记录。 请更正我的疑问。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

您可以使用CTE

    WITH MyCTE 
    AS
    (
       SELECT [FirstName], ROW_NUMBER() OVER(PARTITION BY FirstName ORDER BY FirstName) RN
       FROM Student
    )
    DELETE FROM MyCTE WHERE RN > 1;
    SELECT * FROM Students;

答案 1 :(得分:0)

您正在根据FirstName删除,因此它会删除您桌面上的所有记录,请尝试这样做。

Live Demo

i=143

baseurl = 'https://example.com/listproduct/index/21/' + str(i)

while (i>0):
    i-=1
    print(baseurl)