| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1985 人关注过本帖, 1 人收藏
标题:如何把数据库中相同姓名的记录删掉?
只看楼主 加入收藏
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:3 
程序代码:
CREATE TABLE 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])
INSERT INTO T VALUES (6,[BB],[BB6])
INSERT INTO T VALUES (7,[DD],[BB7])
* 1. 删除重复的记录行
SELECT * FROM T WHERE B IN (SELECT B FROM T GROUP BY B HAVING COUNT(B)=1) INTO ARRAY TT
SELECT T
ZAP
APPEND FROM ARRAY TT
BROWSE
* 2. 保留重复的记录行中的一条记录
* A. 保留 A 字段值最小的那条记录
SELECT * FROM T WHERE B IN (SELECT B FROM T GROUP BY B HAVING COUNT(B)=1) INTO ARRAY TT
DELETE FROM T WHERE  A NOT IN (SELECT MIN(A) FROM T GROUP BY B HAVING COUNT(B)>1)
SELECT T
PACK
APPEND FROM ARRAY TT
BROWSE
* B. 保留 A 字段值最大的那条记录
SELECT * FROM T WHERE B IN (SELECT B FROM T GROUP BY B HAVING COUNT(B)=1) INTO ARRAY TT
DELETE FROM T WHERE  A NOT IN (SELECT MAX(A) FROM T GROUP BY B HAVING COUNT(B)>1)
SELECT T
PACK
APPEND FROM ARRAY TT
BROWSE

坚守VFP最后的阵地
2013-04-25 23:41
快速回复:如何把数据库中相同姓名的记录删掉?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017500 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved