MySQL表student

MySQL删除冗余数据

  • 删除冗余数据,并保留一条
DELETE FROM student WHERE id NOT IN (SELECT MIN(s.id) FROM (SELECT * FROM student) s GROUP BY s.name,s.code,s.course,s.score,s.gender);
DELETE FROM student WHERE id NOT IN (SELECT * FROM (SELECT MIN(s.id) FROM  student s GROUP BY s.name,s.code,s.course,s.score,s.gender)st );

MIN()函数换成MAX()也一样;
如果是DELETE FROM student WHERE id NOT IN (SELECT MIN(s.id) FROM student s GROUP BY s.name,s.code,s.course,s.score,s.gender);,则MySQL报错
You can't specify target table 'student' for update in FROM clause

相关文章:

  • 2022-02-02
  • 2021-07-24
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
猜你喜欢
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
相关资源
相似解决方案