赞
踩
select gene_entrez_id,count(*) a
from diag_gene
GROUP BY gene_entrez_id
HAVING a > 1
原理 分组后如果组内多个数据,找到id小的那条
SELECT MIN(id) min_id FROM diag_gene GROUP BY gene_entrez_id
之后删除不在上面查到的集合中的数据
由于数据库不支持同时查和删除同一个表,所以只能建立一个中间表temp
DELETE FROM diag_gene where id NOT IN (select temp.min_id from ( SELECT MIN(id) min_id FROM diag_gene GROUP BY gene_entrez_id) temp) ;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。