需求:数据库中存在名称重复的数据,删除重复的只保留一条。
方法1:使用distinct
DELETE FROM company_info WHERE id not in (select a.id from (SELECT *, count(DISTINCT company_name) FROM `company_info` GROUP BY company_name) a );
方法2: 使用row_number over
DELETE FROM company_info WHERE id in (
SELECT id from (
SELECT *, row_number() over (partition by company_name) as rn from company_info) a
where a.rn > 1)