1.查询重复值:

select code,count(*) as count from hospital group by code having count>1;

该语句查询code重复值大于1的记录

2.删除重复:

DELETE FROM hospital 
WHERE
    id NOT IN (SELECT 
        dt.minno
    FROM
        (SELECT 
            MIN(id) AS minno
        FROM
            hospital
        GROUP BY code) dt);

该语句保留id最小的记录,其余code重复的记录全部删除

posted on 2019-08-09 16:48  二豆  阅读(3946)  评论(0编辑  收藏  举报