易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

mysql中文乱码

第一步:修改数据库配置文件my.ini
客户端的默认字符编码:
default-character-set=utf8
服务器端的默认字符编码
default-character-set=utf8
第二步:重新启动mysql数据库
net stop mysql
net start mysql
第二步:修改applicationContent.xml
修改url属性,将其改为:jdbc:mysql://localhost:3306/member?useUni ......

mysql set names 问题

mysql set names 问题
mysql_query("set names 'utf8'");
一直以来总以为set names 是用来设置msyql 的字符集的,最近作个东西才发现自己认识上的错误,
查一下手册
SET NAMES ‘x‘语句与这三个语句等价:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> ......

介绍mysql数据库下show命令的主要用法


  
  本文主要介绍mysql数据库下show命令的主要用法:
  a. show tables或show tables from database_name; -- 显示当前数据库中所有表的名称。
  b. show databases; -- 显示mysql中所有数据库的名称。
  c. show columns from table_name from database_name; 或show columns from database_name.table_n ......

mysql替换数据库中的部分内容

  例子:将cdb_pms表subject字段中的Welcom to替换成 欢迎光临
UPDATE `cdb_pms`
SET `subject` = REPLACE(`subject`, ‘Welcome to’, ‘欢迎光临’)
WHERE INSTR(`subject`,’Welcome to’) < 0 替换cdb_posts表的message字段,将“viewthread.php?tid=3989”替换成“viewthread.php?tid=16546” U ......

如何重启MySQL服务

 RedHat Linux (Fedora Core/Cent OS)
1.启动:/etc/init.d/mysqld start
2.停止:/etc/init.d/mysqld stop
3.重启:/etc/init.d/mysqld restart
Debian / Ubuntu Linux
1.启动:/etc/init.d/mysql start
2.停止:/etc/init.d/mysql stop
3.重启:/etc/init.d/mysql restart
Windows
1.点击“开始&rdq ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号