方法一:
第一步 創建 一個 baijia_ming12His table 表結構和 你的表 一樣
DROP TABLE IF EXISTS `baijia_ming12His`;
CREATE TABLE `baijia_ming12His` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`xid` int(30) NOT NULL,
`name` varchar(250) NOT NULL,
`sex` int(2) NOT NULL,
`geshu` int(2) NOT NULL,
`szm` varchar(10) DEFAULT '0',
`fenshu` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=451517 DEFAULT CHARSET=utf8;
第二步 在你的表 查詢 需要的數據
select min(a.xid) xid, min(a.name) name, min(a.sex) sex, min(a.geshu) geshu, min(a.szm) szm, min(a.fenshu) fenshu from baijia_ming12 a group by a.name, a.sex order by xid
把 查詢出來的 數據 插入 到 剛才的 臨時表
方法二:
DELETE from baijia_ming12 where (baijia_ming12.name,baijia_ming12.sex) in ( SELECT t.name,t.sex from
( select baijia_ming12.name,baijia_ming12.sex from baijia_ming12 group by baijia_ming12.name,baijia_ming12.sex having count(*) > 1) as t)
and (baijia_ming12.id not in ( SELECT tp.id from (
select min(baijia_ming12.id) as id from baijia_ming12 group by baijia_ming12.name,baijia_ming12.sex having count(*)>1) as tp) )
*