注:文章内容来源于网络,真实性有待确认,请自行甄别。
vfp中如何删除重复数据有一个数据库,格式如下idnameage
发表于:2024-10-24 00:00:00浏览:5次
问题描述:有一个,格式如下
id name age code
1 aaa 10 100
2 aab 11 101
3 aac 13 100
4 aad 11 102
5 acc 10 101
如何将code字段中相同的记录删除呢?
用一句SQL是可以实现的,但是只能保留重复行中的最大或者最小ID的那一行。没办法,你连个表名都不给,只好假定表名是:table_name。
语句如下:
delete from table_name
where code in (select code from table_name group by code having count(code) > 1) and
id not in (select max(id) from table_name group by code having count(code) > 1) ;
栏目分类全部>