查找数据库中的重复记录(多个字段):
SELECT * FROM wcs_best_fitness_individual WHERE (spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo) IN
(SELECT spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo FROM wcs_best_fitness_individual
GROUP BY spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*) >1);
查找数据库中多余的重复记录(多个字段,已保留一条数据):
SELECT * FROM wcs_best_fitness_individual WHERE (spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo) IN
(SELECT spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo FROM wcs_best_fitness_individual
GROUP BY spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*) >1) AND
id NOT IN (SELECT id FROM wcs_best_fitness_individual GROUP BY
spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*)>1);
SELECT * FROM wcs_best_fitness_individual WHERE (spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo) IN
(SELECT spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo FROM wcs_best_fitness_individual
GROUP BY spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*) >1);
查找数据库中多余的重复记录(多个字段,已保留一条数据):
SELECT * FROM wcs_best_fitness_individual WHERE (spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo) IN
(SELECT spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo FROM wcs_best_fitness_individual
GROUP BY spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*) >1) AND
id NOT IN (SELECT id FROM wcs_best_fitness_individual GROUP BY
spokeCounts,isSpokeClosure,deflectionAngleOne,deflectionAngleTwo HAVING COUNT(*)>1);
本文介绍如何使用SQL查询来找出数据库表中的重复记录,并提供两种查询方法:一种是查找所有重复记录,另一种是在考虑冗余数据时仅保留一条记录。
1000

被折叠的 条评论
为什么被折叠?



