重复的数据可能有这样两种情况,第一种:表中只有某些字段一样,第二种:两行记录完全一样.第一.对于部分字段重复数据的删除 先来谈谈如何查询重复的数据吧. 下面语句可以查询出那些数据是重复的:select 字段1,字段2,count(*) from 表名 group by 字段1,字段2 having count(*) > 1 将上面的>号改为=号就可以查询出没有重复的数据了. 想要删除这些重复的数据,可以使用下面语句进行删除delete f…
需求: 项目中有一张表大概有7000多万条数据,造成表空间已满,需要清理部分数据,打算清理3000万. 2B 做法: delete from table_name where ID > '40000000'; 备注:select count(1) from table_name where ID > 'his_batch_4000000'; 的结果大概有3000万条数据. 影响: 删了N个小时也没执行完,最终强制停止,造成表被锁.(没有管理员权限,需要联系DBA 才能解锁) 改进: decl…
where条件表达式 --统计函数 Select count(1) from student; --like模糊查询 --统计班上姓张的人数 select count(*) from student where realName like '张%'; --统计班上张姓两个字的人数 select count(*) from student where realName like '张_'; --统计班上杭州籍的学生人数 select count(*) from student where home…