删除重复记录并保留其中记录号最大的一条,用 sql 语如何写
一表中有N条重复记录,现要删除并保留记录号最大的一条,SQL删除语句如何写?[ 本帖最后由 sylknb 于 2014-4-29 12:14 编辑 ]
*--- 保留字段A中最大值的那一行 CREATE CURSOR T (A I,B C(2),C C(3)) INSERT INTO T VALUES (1,[AA],[BB1]) INSERT INTO T VALUES (2,[AA],[BB2]) INSERT INTO T VALUES (3,[CC],[BB3]) INSERT INTO T VALUES (4,[AA],[BB4]) INSERT INTO T VALUES (5,[CC],[BB5]) DELETE T FROM (SELECT * FROM T WHERE ; B IN (SELECT B FROM T GROUP BY B HAVING COUNT(B)>1) ; AND A NOT IN (SELECT MAX(A) FROM T GROUP BY B HAVING COUNT(B)>1)) A WHERE T.A=A.A MESSAGEBOX(_TALLY) SELECT T BROWSE