MySQL查询表内重复记录
MySQL查询表内重复记录
查询及删除重复记录的方法
(一)
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
(二)
比方说
在A表中存在一个字段“name”,
而且不同记录之间的“name”值有可能会相同,
现在就是需要查询出在该表中的各记录之间,“name”值存在重复的项;
Select Name,Count(*) from A Group By Name Having Count(*) > 1
如果还查性别也相同大则如下:
Select Name,sex,Count(*) from A Group By Name,sex Having Count(*) > 1
(三)
方法一
declare @max integer,@id integer
declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) >; 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
delete from 表名 where 主字段 = @id
fetch cur_rows into @id,@max
end
close c
相关文档:
select
count(*) as mcount ,
left(create_time,10) as ptime ,
count(if(receive_msg is null,id,null)) as nullcount ,
count(if(receive_msg = '1',receive_msg,null)) as apfcount ,
count(if(receive_msg = '2',receive_msg,null)) as dttcount ,
count(if(receive_msg = '3',receive_ms ......
Scale Out:横向扩展,增加处理节点提高整体处理能力
Scale Up:纵向扩展,通过提升单个节点的处理能力达到提升整体处理能力的目的
Replication
MySQL的replication是异步的,适用于对数据实时性要求不是特别关键的场景。slave端的IO线程负责从master读取日志,SQL线 程专门负责在slave端应用从master读过来的日志(早期 ......
1.加载mysql驱动包Properties->java Build Path->Libraries->Add External JARs...
2.Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名?user=root&password=密码"); ......
一 Apache 的安装
1 Apache 的安装
2 同意协议
3 接着 "Next "
4 填写 域名(network domain) 服务器的名称 (Server Name) 管理者邮箱(Administrator's Email)
5 安装类型
6 选择安装路径
7 点击“install ” 继续
8 开始安装
9 安装结束
二 MySql的安装
......