如题,数据库记录共有100万条,我目前查找的sql 是select count(content) as sum,tables.*  from tables where content GROUP BY content  HAVING count(content)>1
效率不高并且有些重复信息没有搜索出来,请教大家有没有更好的办法? 谢谢!

解决方案 »

  1.   

    try:
    select a.* from tables a inner join
    (select content from tables GROUP BY content  HAVING count(content)>1) b
    on a.`content`=b.`content`
    在content字段上建立索引
      

  2.   

    谢谢!楼上专家的这种方法可以,还有更高效的吗?记录是这样的
    sid                 id                 datetime                        content                                                                                                                         status            catgory
    302273   10267    2009-03-03 10:37:06   鸡营养还不错地。。所以还蛮喜欢吃的   杭州宋城大饭店地处上城区。          1                    餐饮
                                                                                      宋城大饭店是宋都集团所属企业,于97年底开始营业,距杭州火车城站
                                                                                      800米,...  
    要求的结果就是与 “营养还不错地。。所以还蛮喜欢吃的   杭州宋城大饭店地处上城区。宋城大饭店是宋都集团所属企业,于97年底开始营业,距杭州火车城站800米,...  ”相同的都找出来并且标注status=0
      

  3.   

    谢谢!楼上专家的这种方法可以,还有更高效的吗?记录是这样的
    sid                 id                 datetime                        content                                                                                                                         status            catgory
    302273   10267    2009-03-03 10:37:06   鸡营养还不错地。。所以还蛮喜欢吃的   杭州宋城大饭店地处上城区。          1                    餐饮
                                                                                      宋城大饭店是宋都集团所属企业,于97年底开始营业,距杭州火车城站
                                                                                      800米,...  
    要求的结果就是与 “营养还不错地。。所以还蛮喜欢吃的   杭州宋城大饭店地处上城区。宋城大饭店是宋都集团所属企业,于97年底开始营业,距杭州火车城站800米,...  ”相同的都找出来并且标注status=0
      

  4.   

    谢谢!楼上专家的这种方法可以,还有更高效的吗? :
    应该是最快的方法相同的都找出来并且标注status=0 
    update tt a inner join
    (select content from tables GROUP BY content  HAVING count(content)>1)
     b
    on a.`content`=b.`content` 
    set  a.status=0
      

  5.   

    update yourTable a inner join (select content from yourTable group by content having count(*)>1) b 
    on a.`content` = b.`content` 
    set a.status=0
      

  6.   

    估计你的content上没有索引,或者试试
    update yourTable a
    set status=0
    where exists(select id from yourTable where `content` =a.`content` and id!=a.id);
      

  7.   

    谢谢! sorry! 我忘了还有一点,我想每个重复需要保留一条,其他的替换掉,该怎么写呐?
      

  8.   

    谢谢! sorry! 我忘了还有一点,我想每组重复需要保留一条,其他的替换掉,该怎么写呐?
      

  9.   

    update tt a inner join
    (select content,max(id) as ma from tables GROUP BY content  HAVING count(content)>1)
    b
    on a.`content`=b.`content` and a.id=b.ma
    set  a.status=0也可以和MAX->MIN,假设你以ID为唯一标识的字段
      

  10.   


    update yourTable a
    set status=0
    where exists(select id from yourTable where `content` =a.`content` and id<a.id);