其他分享
首页 > 其他分享> > 2021-11-10

2021-11-10

作者:互联网

数据库按照多字段去重

sql如下:

DELETE
FROM
student
WHERE
id IN (
select m.id from

(SELECT
    id
FROM
    student A,
    ( SELECT StuName,ClassName,address FROM student GROUP BY StuName,ClassName,address HAVING COUNT(*) > 1 ) B
WHERE
    A.StuName  = B.StuName 
    AND A.ClassName  = B.ClassName
  and A.address=B.address
AND A.id NOT IN ( SELECT MIN( id ) AS ID FROM student GROUP BY StuName,ClassName,address HAVING COUNT(*) > 1 )) m
)

标签:11,10,StuName,ClassName,2021,student,address,id,SELECT
来源: https://blog.csdn.net/qq_42672764/article/details/121245973