Chinaunix首页 | 论坛 | 博客
  • 博客访问: 80178
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-02 20:25
文章分类

全部博文(31)

文章存档

2015年(2)

2014年(29)

我的朋友

分类: Mysql/postgreSQL

2014-08-26 10:33:20

ex:person(id,fname,lname). name(fname+lname)一样算重复。

1.  过滤重复数据
        select distinct fname,lname from person;
        select id,fname,lname from person group by fname,lname ;
   都需要using temporary; Using filesort。 但distinct 方式取不到id值

2. 统计重复数据

       select id,fname,lname from person group by fname,lname having count(id)>1 ;

3.统计无重复数据

       select id,fname,lname from person group by fname,lname having count(id)=1 ;

4.去重
     delete from person where id not in ( select id form ( select id,fname,lname from person group by fname,lname ) as tab1 );
     或者
      create table tmp select * from person group by fname,lname;
     drop table 
person;
     alter table tmp rename to person;
     一系列添加索引,约束操作,自增操作




   

阅读(742) | 评论(0) | 转发(0) |
0

上一篇:4. Prepared statement

下一篇:6. 表设计

给主人留下些什么吧!~~